Sandoval0992
Sandoval0992

Reputation: 1367

Why is gson library setting integer values to zero when converting json response to ArrayList<Object>?

I'm trying to convert a json format response from a web service into an ArrayList<Stop> object.

Before converting the json response into a java object I made sure the database is retreiving all the data in a proper manner, see the image below.

enter image description here

However after converting the json response and debugging the android app I realized that the value of all the integer fields has been set to zero. The fields stopId and journeyId correspond to a PRIMARY_KEY and FOREIGN_KEY respectively in the database.

enter image description here

This is the snipet of code I wrote to do this. enter image description here

Thanks in advance for all your help.

Upvotes: 0

Views: 518

Answers (1)

Luiz Fernando Salvaterra
Luiz Fernando Salvaterra

Reputation: 4182

Try to change your model class according Camel Case Sensitive, change stop_id to stopId and journey_id to journeyId. Or configure your Gson according your necessities:

Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
String jsonRepresentation = gson.toJson(someObject);
System.out.println(jsonRepresentation);

Upvotes: 1

Related Questions