领域升级和改造后的问题

时间:2018-07-13 13:09:22

标签: android jackson realm retrofit rx-android

我在致电翻新服务电话时遇到错误/异常。在我的项目中升级Realm和Retrofit版本后,我收到此异常,并且当前我使用的是rxJava,realm和Retrofit的当前版本。

我正在使用JacksonConverterFactory并创建了自己的对象映射器类。

请帮助解决该异常。

[
  {
    "_id": {
      "medName": "MedC"
    },
    "count": 1,
    "percentage": "50%"
  },
  {
    "_id": {
      "medName": "MedD"
    },
    "count": 1,
    "percentage": "50%"
  },
  {
    "_id": {
      "medName": "MedB"
    },
    "count": 2,
    "percentage": "100%"
  },
  {
    "_id": {
      "medName": "MedA"
    },
    "count": 1,
    "percentage": "50%"
  }
]

例外

P.N :- HousingComplex is a model class and extends as realmObject
public class HousingComplex extends RealmObject {
    Boolean isAddressAllowed;
    Boolean isLocalityAllowed;
    Boolean isPetsAllowed;
    Boolean isCityAllowed;
    Boolean isNameAllowed;
    String metadata;


    public Boolean getAddressAllowed() {
        return isAddressAllowed;
    }

    public void setAddressAllowed(Boolean addressAllowed) {
        isAddressAllowed = addressAllowed;
    }

    public Boolean getLocalityAllowed() {
        return isLocalityAllowed;
    }

    public void setlocalityAllowed(Boolean localityAllowed) {
        isLocalityAllowed = localityAllowed;
    }

    public Boolean getPetsAllowed() {
        return isPetsAllowed;
    }

    public void setPetsAllowed(Boolean petsAllowed) {
        isPetsAllowed = petsAllowed;
    }

    public Boolean getCityAllowed() {
        return isCityAllowed;
    }

    public void setCityAllowed(Boolean cityAllowed) {
        isCityAllowed = cityAllowed;
    }

    public Boolean getNameAllowed() {
        return isNameAllowed;
    }

    public void setNameAllowed(Boolean nameAllowed) {
        isNameAllowed = nameAllowed;
    }

    public String getMetadata() {
        return metadata;
    }

    public void setMetadata(String metadata) {
        this.metadata = metadata;
    }
}

2 个答案:

答案 0 :(得分:0)

错误非常明显。

Caused by: java.lang.IllegalStateException: HousingComplex doesn't have a primary key.

因此,您需要向模型类添加一个主键。例如

 @PrimaryKey 
 private int id;

答案 1 :(得分:0)

我认为您这次应该切换为使用

@RealmClass
public class HousingComplex implements RealmModel {
}

您应该只将分离的对象提供给杰克逊序列化器:

List<HousingComplex> detached = realm.copyFromRealm(housingComplexes);
apiService.send(detached);