Object in java contains a JSON, I want to get the JSON information and popular my object attributes [closed]

0

It is the following, I have the GPS object, it is with a json as follows the image, I want to get the data of the field code and field name and place them within the attributes of the GPS object. FOLLOW IMAGE

How can I do this?

I tried this way, but no event

this.nome = lista.get(acessorio).nome;
this.codigo = lista.get(acessorio).codigo;
    
asked by anonymous 09.01.2017 / 04:52

1 answer

1

There is already a library that does this, populates the objects and converts the object to json.

To popular the object:

Gson gson = new Gson();
Acessorio gps = gson.fromJson(json, Acessorio.class);

Converts the object to json:

Gson gson = new Gson();
String json = gson.toJson(objeto);

objects should be a JavaBeans .

Include dependency Maven to your project or download Jar's .

    
09.01.2017 / 06:17