Синтаксический анализ JSON со схемой Retrofit-model

ошибка :

Метод thrown ‘ java.ленг.NullPointerException ‘ исключение. Не удается оценить pl.пользователь сети.eonbeacon.место хранения.EonBeaconModel.toString()

Я пытаюсь разобрать JSON с помощью retrofit. У меня есть JSON от сервера, который выглядит так:

{
  "data": {
    "list": [
      {
        "id": 58,
        "beacon_id": "58",
        "bridge_id": null,
        "mesh_id": null,
        "name": "eon_3c",
        "location": "abcdlk",
        "mac_address": "3c:cf:82:8a:e7:fe",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": "99",
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "33",
          "minor": "344",
          "tx_power": "7",
          "interval": "400",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      },
      {
        "id": 56,
        "beacon_id": "56",
        "bridge_id": null,
        "mesh_id": null,
        "name": "Eon_e6",
        "location": "test",
        "mac_address": "e6:f5:8a:94:b8:c7",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": null,
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "2591",
          "minor": "0",
          "tx_power": "10",
          "interval": "2593",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      },
      {
        "id": 57,
        "beacon_id": "57",
        "bridge_id": "13",
        "mesh_id": "278",
        "name": "Marta B",
        "location": "lk",
        "mac_address": "e1:4b:64:c3:80:e2",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": "97",
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "325",
          "minor": "10",
          "tx_power": "8",
          "interval": "610",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      }
    ]
  },
  "ver": 1,
  "time": 1475671202,
  "status": 1,
  "status_msg": ""
}

Мой корневой класс ответов выглядит следующим образом :

public class BasicResponse<T> {
    @Expose
    public T data;
    @Expose
    public int ver;
    @Expose
    public long time;
    @Expose
    public byte status;
    @Expose
    public String status_msg;
}

До этого момента все выглядит хорошо. Теперь я пытаюсь проанализировать данные :

public class BeaconResponse {
    @Expose
    public int id;
    @Expose
    public long beacon_id;
    @Expose
    public long bridge_id;
    @Expose
    public long mesh_id;
    @Expose
    public String name;
    @Expose
    public String location;
    @Expose
    public String mac_address;
    @Expose
    public String firmware;
    @Expose
    public String pcb_revision;
    @Expose
    public byte battery_level;
    @Expose
    public String password;
    @Expose
    @SerializedName("ib")
    public Ib ib;
    @Expose
    @SerializedName("euid")
    public Euid euid;
    @SerializedName("eeid")
    @Expose
    public Eeid eeid;
    @SerializedName("eurl")
    @Expose
    public Eurl eurl;
    @SerializedName("etlm")
    @Expose
    public Etlm etlm;
    @Expose
    public int assigned_bridge_id;

Здесь начинается проблема. Все прекрасно разбирается, кроме объектов-euid,eeid,eurl,etlm, ib. Когда я изменяю их имена классов, дооснащайте Парс все, кроме них — они пустые. Когда я изменяю имена классов в соответствии с ключом из JSON, у меня есть ошибка модернизации. Я использовал POJO, и он создал очень похожий класс на мой. Есть идеи, где проблема ? :/

Вот мой вызов модернизации :

@Subscribe
    public void getUserBeacons(GetBeaconsListCommand command) {
        Callback<BasicResponse<BeaconsListResponse>> callback = new Callback<BasicResponse<BeaconsListResponse>>() {
            @Override
            public void success(BasicResponse<BeaconsListResponse> basicResponse, Response response) {
                if (ResponseStatus.SUCCESS.statusCode == basicResponse.status)
                    EventBus.post(new BeaconsListFetchedEvent(basicResponse.data));
                else
                    EventBus.post(new NetworkFailureEvent(ResponseStatus.getByStatus(basicResponse.status), basicResponse.status_msg));
            }

            @Override
            public void failure(RetrofitError error) {
            }
        };
        service.beaconsList(callback);
    }

Модели Euid,Eeid :

public class EuidModel extends Model {

    @Expose
    public boolean  turn_on;
    @Expose
    public  String namespace;
    @Expose
    public String  instance;
    @Expose
    public  int tx_power;
    @Expose
    public long  interval;

    public boolean isTurn_on() {
        return turn_on;
    }

    public void setTurn_on(boolean turn_on) {
        this.turn_on = turn_on;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getInstance() {
        return instance;
    }

    public void setInstance(String instance) {
        this.instance = instance;
    }

    public int getTx_power() {
        return tx_power;
    }

    public void setTx_power(int tx_power) {
        this.tx_power = tx_power;
    }

    public long getInterval() {
        return interval;
    }

    public void setInterval(long interval) {
        this.interval = interval;
    }


    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }
public class EeidModel extends Model {

    @Column
    public boolean turn_on;
    @Column
    public int tx_power;
    @Column
    public int interval;
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

1 ответ

  1. Попробуйте эту модель, и я уверен, что она будет работать хорошо, то:-

    public class model {
    
        private DataBean data;
    
        private int ver;
        private int time;
        private int status;
        private String status_msg;
    
        public DataBean getData() {
            return data;
        }
    
        public void setData(DataBean data) {
            this.data = data;
        }
    
        public int getVer() {
            return ver;
        }
    
        public void setVer(int ver) {
            this.ver = ver;
        }
    
        public int getTime() {
            return time;
        }
    
        public void setTime(int time) {
            this.time = time;
        }
    
        public int getStatus() {
            return status;
        }
    
        public void setStatus(int status) {
            this.status = status;
        }
    
        public String getStatus_msg() {
            return status_msg;
        }
    
        public void setStatus_msg(String status_msg) {
            this.status_msg = status_msg;
        }
    
        private static class DataBean {
    
            private List<ListBean> list;
    
            public List<ListBean> getList() {
                return list;
            }
    
            public void setList(List<ListBean> list) {
                this.list = list;
            }
    
            static class ListBean {
                private int id;
                private String beacon_id;
                private Object bridge_id;
                private Object mesh_id;
                private String name;
                private String location;
                private String mac_address;
                private String firmware;
                private String pcb_revision;
                private String battery_level;
                private String password;
    
                private IbBean ib;
    
                private EuidBean euid;
    
                private EeidBean eeid;
    
                private EurlBean eurl;
    
                private EtlmBean etlm;
                private Object assigned_bridge_id;
    
                public int getId() {
                    return id;
                }
    
                public void setId(int id) {
                    this.id = id;
                }
    
                public String getBeacon_id() {
                    return beacon_id;
                }
    
                public void setBeacon_id(String beacon_id) {
                    this.beacon_id = beacon_id;
                }
    
                public Object getBridge_id() {
                    return bridge_id;
                }
    
                public void setBridge_id(Object bridge_id) {
                    this.bridge_id = bridge_id;
                }
    
                public Object getMesh_id() {
                    return mesh_id;
                }
    
                public void setMesh_id(Object mesh_id) {
                    this.mesh_id = mesh_id;
                }
    
                public String getName() {
                    return name;
                }
    
                public void setName(String name) {
                    this.name = name;
                }
    
                public String getLocation() {
                    return location;
                }
    
                public void setLocation(String location) {
                    this.location = location;
                }
    
                public String getMac_address() {
                    return mac_address;
                }
    
                public void setMac_address(String mac_address) {
                    this.mac_address = mac_address;
                }
    
                public String getFirmware() {
                    return firmware;
                }
    
                public void setFirmware(String firmware) {
                    this.firmware = firmware;
                }
    
                public String getPcb_revision() {
                    return pcb_revision;
                }
    
                public void setPcb_revision(String pcb_revision) {
                    this.pcb_revision = pcb_revision;
                }
    
                public String getBattery_level() {
                    return battery_level;
                }
    
                public void setBattery_level(String battery_level) {
                    this.battery_level = battery_level;
                }
    
                public String getPassword() {
                    return password;
                }
    
                public void setPassword(String password) {
                    this.password = password;
                }
    
                public IbBean getIb() {
                    return ib;
                }
    
                public void setIb(IbBean ib) {
                    this.ib = ib;
                }
    
                public EuidBean getEuid() {
                    return euid;
                }
    
                public void setEuid(EuidBean euid) {
                    this.euid = euid;
                }
    
                public EeidBean getEeid() {
                    return eeid;
                }
    
                public void setEeid(EeidBean eeid) {
                    this.eeid = eeid;
                }
    
                public EurlBean getEurl() {
                    return eurl;
                }
    
                public void setEurl(EurlBean eurl) {
                    this.eurl = eurl;
                }
    
                public EtlmBean getEtlm() {
                    return etlm;
                }
    
                public void setEtlm(EtlmBean etlm) {
                    this.etlm = etlm;
                }
    
                public Object getAssigned_bridge_id() {
                    return assigned_bridge_id;
                }
    
                public void setAssigned_bridge_id(Object assigned_bridge_id) {
                    this.assigned_bridge_id = assigned_bridge_id;
                }
    
                static class IbBean {
                    private String turn_on;
                    private String major;
                    private String minor;
                    private String tx_power;
                    private String interval;
                    private String uuid;
                    private String secure_uuid;
    
                    public String getTurn_on() {
                        return turn_on;
                    }
    
                    public void setTurn_on(String turn_on) {
                        this.turn_on = turn_on;
                    }
    
                    public String getMajor() {
                        return major;
                    }
    
                    public void setMajor(String major) {
                        this.major = major;
                    }
    
                    public String getMinor() {
                        return minor;
                    }
    
                    public void setMinor(String minor) {
                        this.minor = minor;
                    }
    
                    public String getTx_power() {
                        return tx_power;
                    }
    
                    public void setTx_power(String tx_power) {
                        this.tx_power = tx_power;
                    }
    
                    public String getInterval() {
                        return interval;
                    }
    
                    public void setInterval(String interval) {
                        this.interval = interval;
                    }
    
                    public String getUuid() {
                        return uuid;
                    }
    
                    public void setUuid(String uuid) {
                        this.uuid = uuid;
                    }
    
                    public String getSecure_uuid() {
                        return secure_uuid;
                    }
    
                    public void setSecure_uuid(String secure_uuid) {
                        this.secure_uuid = secure_uuid;
                    }
                }
    
                static class EuidBean {
                    private String turn_on;
                    private Object namespace;
                    private Object instance;
                    private Object tx_power;
                    private Object interval;
    
                    public String getTurn_on() {
                        return turn_on;
                    }
    
                    public void setTurn_on(String turn_on) {
                        this.turn_on = turn_on;
                    }
    
                    public Object getNamespace() {
                        return namespace;
                    }
    
                    public void setNamespace(Object namespace) {
                        this.namespace = namespace;
                    }
    
                    public Object getInstance() {
                        return instance;
                    }
    
                    public void setInstance(Object instance) {
                        this.instance = instance;
                    }
    
                    public Object getTx_power() {
                        return tx_power;
                    }
    
                    public void setTx_power(Object tx_power) {
                        this.tx_power = tx_power;
                    }
    
                    public Object getInterval() {
                        return interval;
                    }
    
                    public void setInterval(Object interval) {
                        this.interval = interval;
                    }
                }
    
                static class EeidBean {
                    private String turn_on;
                    private Object tx_power;
                    private Object interval;
    
                    public String getTurn_on() {
                        return turn_on;
                    }
    
                    public void setTurn_on(String turn_on) {
                        this.turn_on = turn_on;
                    }
    
                    public Object getTx_power() {
                        return tx_power;
                    }
    
                    public void setTx_power(Object tx_power) {
                        this.tx_power = tx_power;
                    }
    
                    public Object getInterval() {
                        return interval;
                    }
    
                    public void setInterval(Object interval) {
                        this.interval = interval;
                    }
                }
    
                static class EurlBean {
                    private String turn_on;
                    private Object tx_power;
                    private Object interval;
                    private Object url;
    
                    public String getTurn_on() {
                        return turn_on;
                    }
    
                    public void setTurn_on(String turn_on) {
                        this.turn_on = turn_on;
                    }
    
                    public Object getTx_power() {
                        return tx_power;
                    }
    
                    public void setTx_power(Object tx_power) {
                        this.tx_power = tx_power;
                    }
    
                    public Object getInterval() {
                        return interval;
                    }
    
                    public void setInterval(Object interval) {
                        this.interval = interval;
                    }
    
                    public Object getUrl() {
                        return url;
                    }
    
                    public void setUrl(Object url) {
                        this.url = url;
                    }
                }
    
                static class EtlmBean {
                    private String turn_on;
                    private Object tx_power;
                    private Object interval;
    
                    public String getTurn_on() {
                        return turn_on;
                    }
    
                    public void setTurn_on(String turn_on) {
                        this.turn_on = turn_on;
                    }
    
                    public Object getTx_power() {
                        return tx_power;
                    }
    
                    public void setTx_power(Object tx_power) {
                        this.tx_power = tx_power;
                    }
    
                    public Object getInterval() {
                        return interval;
                    }
    
                    public void setInterval(Object interval) {
                        this.interval = interval;
                    }
                }
            }
        }
    }