0

i am trying to fetch data from Realm and sending it to server using retrofit and for parsing and serializing i am using LoganSquare

  client =  new Retrofit.Builder()
                         .baseUrl(REST_ENDPOINT)
                         .client(okHttpClient)
                         .addConverterFactory(LoganSquareConverterFactory.create())
                         .build();

this is how i am accessing record

Appointment appointments = DB.getInstance(mContext).selectNotSyncAppointmentsData();
        RestApi.AppointmentsDataApi service = getAppointmentsDataApi();
        Call<APResponse> call = service.createUpdateAppointmentsData(appointments);

i am getting following error

createUpdateAppointmentData : onFailure Class io.realm.AppointmentRealmProxy could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?
Hunt
  • 8,215
  • 28
  • 116
  • 256

1 Answers1

0

I am not familiar with how LoganSquare works, but be aware that Realm works with something called proxy classes that extend all your model classes. You can recognise these as they are called <ModelClass>RealmProxy. It looks like you somehow have to find a way to configure LoganSquare to recognise these sub-classes.

Alternatively you can use realm.copyFromRealm(appointments). That will give you an in-memory copy of all the data which are of the correct class.

Christian Melchior
  • 19,978
  • 5
  • 62
  • 53
  • LoganSquare uses APT to generate `$$JsonObjectMapper` classes using the `@JsonObject` and `@JsonField` annotation on the class and its fields respectively. The `LoganSquare` class also places its generated `$$ObjectMapper` classes into a map, mapped in a `new ConcurrentHashMap()`. The problem is that the `RealmProxy` class doesn't get its own `SomethingRealmProxy$$JsonObjectMapper` that would handle the class like a normal `Something`, so the `Map` doesn't contain a `JsonObjectMapper` for the class of `SomethingRealmProxy`, only for `Something`. – EpicPandaForce May 04 '16 at 11:02
  • 1
    If there's any place where such a hacked Mapper could be shoehorned in (without annotating the proxy with `@JsonObject`), it's using the fact that LoganSquare attempts to find the corresponding ObjectMapper once more: `Class> mapperClass = Class.forName(cls.getName() + Constants.MAPPER_CLASS_SUFFIX);` where class suffix is `$$JsonObjectMapper` – EpicPandaForce May 04 '16 at 11:15