问题
I have this json
{"FechaUpdateId":1,"FechaSegundos":635902782941643690,"FechaSegundosBC":635902779020935030}
I execute this command for convert it to object
FechaUpdate dto = new Gson().fromJson(json, FechaUpdate.class);
But I got this result
this is my FechaUpdate class
public class FechaUpdate {
public int getFechaUpdateId() {
return fechaUpdateId;
}
public void setFechaUpdateId(int fechaUpdateId) {
this.fechaUpdateId = fechaUpdateId;
}
public long getFechaSegundosBC() {
return fechaSegundosBC;
}
public void setFechaSegundosBC(long fechaSegundosBC) {
this.fechaSegundosBC = fechaSegundosBC;
}
public long getFechaSegundos() {
return fechaSegundos;
}
public void setFechaSegundos(long fechaSegundos) {
this.fechaSegundos = fechaSegundos;
}
private int fechaUpdateId ;
private long fechaSegundos ;
private long fechaSegundosBC;
}
回答1:
Solved
if you see my private attributes they are
private int fechaUpdateId ;
private long fechaSegundos ;
private long fechaSegundosBC;
I change them by
private int FechaUpdateId ;
private long FechaSegundos ;
private long FechaSegundosBC;
and generate the getter and setters again. the diference is the First letter is UpperCase.
来源:https://stackoverflow.com/questions/35235721/gson-fromjsonjsonresult-myobject-class-return-values-in-0s