2016-04-29 11 views
0

我試圖從Realm獲取數據並將其發送到使用retrofit服務器和解析和序列我使用LoganSquare無法映射到一個JSON對象Logansquare

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

這是怎麼我正在訪問記錄

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

我收到以下錯誤

createUpdateAppointmentData : onFailure Class io.realm.AppointmentRealmProxy could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject? 

回答

0

我對LoganSquare的工作原理並不熟悉,但請注意,Realm使用了可以擴展所有模型類的代理類。您可以識別它們,因爲它們被稱爲<ModelClass>RealmProxy。看起來你必須找到一種方法來配置LoganSquare來識別這些子類。

或者您可以使用realm.copyFromRealm(appointments)。這將爲您提供所有正確類的數據的內存中副本。

+0

LoganSquare使用APT來生成分別使用'@ JsonObject'和'@在類JsonField'註釋及其字段' $$ JsonObjectMapper'類。 LoganSquare類也將其生成的$$ ObjectMapper類放入一個映射中,映射到新的ConcurrentHashMap ()'中。問題在於'RealmProxy'類沒有自己的'SomethingRealmProxy $$ JsonObjectMapper'來處理像普通的'Something'這樣的類,所以'Map'不包含'JsonObjectMapper'類'SomethingRealmProxy',僅用於'Something'。 – EpicPandaForce

+1

如果有地方這樣的黑客攻擊可能映射在被硬塞(不帶註釋的代理'@ JsonObject')任何地方,它的使用LoganSquare試圖找到相應的ObjectMapper一次這樣的事實:'類 mapperClass =的Class.forName( cls.getName()+ Constants.MAPPER_CLASS_SUFFIX);'類的後綴是'$$ JsonObjectMapper' – EpicPandaForce