1

I am using Room and Volley to get data from a generic web service that only returns column and value for each row of the selected table.

The thing is that I don't want to modify the web service to return a specific data tree by table.

So having :

{"columns": {
    "0": [{"column":"name","value":"pepe"},{"column":"age","value":20}],
    "1": [{"column":"name","value":"paco"},{"column":"age","value":23}]
}}

.. I want to be able to fit that response creating an instance of the following class for example...

public class Person {

String name = "";
int age = 0;

}

So people make the pojo from their responses to consume each object with gson like...

{"persons": {
    "person": [{"name":"pepe","age":20},{"name":"paco","age":23}]
}}
Person p = gson.fromJson(jsonString, Person.class);

So i want to be able as im invoking the table person in the web service to return that generic json and convert it to a custom class because the columns are the same in the response and in the class itself.

Is there a possibility to load that column name and ask the object the type of data and parse it properly in a few lines of code...? ...Or ill need to loop de JSONObject to get the specific variable to later build the object in the constructor...?

THX

Rafudus
  • 11
  • 2

0 Answers0