1
Hello, I’m getting the JSON string below, but I can’t put the values in the Class I created, all values are null.
Any hint?
JSON
{"USDT":{"code":"USD",
"codein":"BRLT",
"name":"Dólar Turismo",
"high":"4.09",
"low":"3.9",
"varBid":"0.13",
"pctChange":"3.103",
"bid":"4.08",
"ask":"4.32",
"timestamp":"1558121820000",
"create_date":"2019-05-17 16:39:00"
}
}
Making the deserialization:
// Deserialization
//Gson gson = new Gson();
Moedas moedaDia = new Gson().fromJson(response.json, Moedas.class);
String line = "";
result.setResult(moedaDia);
Class Coins
public class Moedas {
public List<MoedaDia> USD;
public Moedas( List<MoedaDia> USD) {
this.USD = USD;
}
public List<MoedaDia> getValue() {
return USD;
}
public void setValue(List<MoedaDia> value) {
this.USD = value;
}
}
Moedadia:
public class MoedaDia {
public String code; //": "BRL",
public String codein; //": "BRL",
public String name; //": "Dólar Comercial",
public float high; //": "3,9766",
public float low; //": "3,9748",
public float varBid; //": "0,0021",
public float pctChange; //: "0,05",
public float bid; //": "3,9765",
public float ask; //": "3,9767",
public String timestamp; //": "1557873008",
public String create_date; //": "2019-05-14 21:00:05"
public MoedaDia(String code, String codein, String name, float high, float low, float varBid, float pctChange, float bid, float ask, String timestamp, String create_date) {
this.code = code;
this.codein = codein;
this.name = name;
this.high = high;
this.low = low;
this.varBid = varBid;
this.pctChange = pctChange;
this.bid = bid;
this.ask = ask;
this.timestamp = timestamp;
this.create_date = create_date;
}
}
I found this error I tried the following Solutions: 1) Turning on/off serializeNulls() in my typeadapater while serializing Certain Fields like Follows: Boolean Current = out.getSerializeNulls(); out.setSerializeNulls(true); out.name("fieldName"). value(someValue); out.setSerializeNulls(false); This didn’t work Unfortunately. 2) Creating two Different Gson’s with serializeNulls setup differently. Then when serializing Choosing between the two gson’s based on what I was serializing. That littered my code and seems inefficient because of the Reflection.
– NewSystemsUnlimited
Ask the question. Facilitates the reading of others
– absentia