Gson().fromJson(jsonResult, Myobject.class) return values in 0's

拟墨画扇 提交于 2020-01-07 03:08:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!