How to convert an object to Kotlin of type Any! to another one that is possible to access the fields?

Asked

Viewed 237 times

0

Good morning,

I’m having a bit of a problem getting solved on a project. I am trying to make an application that will communicate with the ERP odoo, however, this ERP uses the xml-rpc protocol for your requests.

To make the requests I am using the axml-rpc lib for android. It is a library made in java, but it seems to be working. When I call a remote odoo function, lib returns me an Any! object with the answers, but I can’t access the information.

Is it possible to access this Hashmap within the name variable or does this blue color indicate a problem? Thanks in advance!

Ps: I’ve tried several Caps, but none worked.

inserir a descrição da imagem aqui

  • You can post an example of payload received in the communication?

  • And how would I check the payload? I would have to use Postman?

  • Well, only you can answer that. But yes, usually using Postman, Fiddler or SOAPUI you can

  • I’ll see what I can do, unfortunately this api doesn’t have much documentation. But in the current state, it is not possible to access the content of the variables even if Debugger says that they contain the date? Initially I did a test with python and it was very quiet communication.

  • When you cast it, does it make a mistake? In this reply one cast Any pra List: https://stackoverflow.com/questions/45107473/how-to-cast-any-to-a-list-in-kotlin

  • If I try a cast with as, I get the following exception: Caused by: java.lang.Classcastexception: java.lang.Object[] cannot be cast to java.util.List When do I use as? , returns null.

Show 1 more comment

1 answer

1

I would recommend you to understand what the library does in Java (reading the documentation), what are the guys she works with, then transpose to Kotlin.

According to the documentation, you are receiving a array (which is represented in the library as a Object[] in Java). Within this array, based on the print, there is a struct (represented in the library by a Map<String,Object>)

Translating this initial structure, you would have in Kotlin:

  • A Array<Any> - Equivalent to Object[]
  • Inside the array, a Map<String, Any>
  • Thanks for the explanation! I had already taken a look at the documentation, but it still doesn’t work to access the Map. .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.