Realm.IO - 无法映射Json

时间:2015-05-13 09:14:58

标签: java android json realm

我有以下JSON:

[
  {
    "organizationId": {
      "aggregateId": "7cfaf5c0-127a-4cfc-b73b-52a35fd02ffd"
    },
    "organizationName": "OrgName1",
    "address": {
      "city": {
        "cityName": "CItyName1",
        "population": 5
      },
      "region": {
        "regionName": "RegionName1",
        "city": null
      },
      "street": "Street1",
      "houseNumber": "HouseNumber1",
      "zipCode": "1000001"
    },
    "phoneNumber": "123456781",
    "faxNumber": "7894653121"
  }
]

组织模式

    public class Organization extends RealmObject{

        private OrganizationId organizationId;
        private String organizationName;
        private Address address;
        private String phoneNumber;
        private String faxNumber;
...

public class OrganizationId extends RealmObject {

    private String aggregateId;//3a53ac71-e5e0-4b5a-83ae-ff81931d30be
...

public class Address extends RealmObject {

    private City city;
    private Region region;
    private String street;
    private String houseNumber;
    private String zipCode;
...

public class City extends RealmObject
{
    private String cityName;
    private int population;
...

public class Region extends RealmObject {

    private String regionName;
    private City city;
...

从HTTP获得json。转换为字符串。然后使用createAllFromJson方法

        String json = new String(response, "UTF-8");
        Realm realm = Realm.getInstance(context);
        realm.createAllFromJson(Organization.class, json);

但这会产生以下错误:

  

java.lang.RuntimeException:io.realm.exceptions.RealmException:可以   没有映射Json               在com.loopj.android.http.AsyncHttpResponseHandler.onUserException(AsyncHttpResponseHandler.java:313)               在com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:404)               在com.loopj.android.http.AsyncHttpResponseHandler $ ResponderHandler.handleMessage(AsyncHttpResponseHandler.java:184)               在android.os.Handler.dispatchMessage(Handler.java:110)               在android.os.Looper.loop(Looper.java:193)               在android.app.ActivityThread.main(ActivityThread.java:5292)               at java.lang.reflect.Method.invokeNative(Native Method)               在java.lang.reflect.Method.invoke(Method.java:515)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:824)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)               at dalvik.system.NativeStart.main(Native Method)        引起:io.realm.exceptions.RealmException:无法映射Json               在io.realm.Realm.createAllFromJson(Realm.java:680)               at io.realm.Realm.createAllFromJson(Realm.java:732)               at uz.sunet.wm.da​​ta.Api $ 1.onSuccess(Api.java:61)               在com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:360)   在com.loopj.android.http.AsyncHttpResponseHandler $ ResponderHandler.handleMessage(AsyncHttpResponseHandler.java:184)   在android.os.Handler.dispatchMessage(Handler.java:110)   在android.os.Looper.loop(Looper.java:193)   在android.app.ActivityThread.main(ActivityThread.java:5292)   at java.lang.reflect.Method.invokeNative(Native Method)   在java.lang.reflect.Method.invoke(Method.java:515)   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:824)   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)   at dalvik.system.NativeStart.main(Native Method)        引起:java.lang.IllegalStateException:读取事务期间的可变方法调用。               at io.realm.internal.Table.throwImmutable(Table.java:1639)               at io.realm.internal.Table.checkImmutable(Table.java:1245)               at io.realm.internal.Table.addEmptyRow(Table.java:368)               at io.realm.Realm.createObject(Realm.java:1037)               at io.realm.OrganizationRealmProxy.createOrUpdateUsingJsonObject(OrganizationRealmProxy.java:236)               at io.realm.RealmJsonImpl.createOrUpdateUsingJsonObject(RealmJsonImpl.java:35)               at io.realm.Realm.createAllFromJson(Realm.java:678)   at io.realm.Realm.createAllFromJson(Realm.java:732)   at uz.sunet.wm.da​​ta.Api $ 1.onSuccess(Api.java:61)   在com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:360)   在com.loopj.android.http.AsyncHttpResponseHandler $ ResponderHandler.handleMessage(AsyncHttpResponseHandler.java:184)   在android.os.Handler.dispatchMessage(Handler.java:110)   在android.os.Looper.loop(Looper.java:193)   在android.app.ActivityThread.main(ActivityThread.java:5292)   at java.lang.reflect.Method.invokeNative(Native Method)   在java.lang.reflect.Method.invoke(Method.java:515)   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:824)   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)   在dalvik.system.NativeStart.main(本地方法)

我检查了组织内的所有模型。一切似乎都很好。但是当我跑到前面说错误之前。如何解决这个问题?

0 个答案:

没有答案