Reputation: 23
please help me :< If i`m without extend my model with realm it good,but with realm all my items are invisible :<
there are code
My model:
@RealmModule(library = true, allClasses = true)
public class Books extends RealmObject {
@Expose
@SerializedName("photo")
private String photo;
@Expose
@SerializedName("rate")
private Integer rate;
@Expose
@SerializedName("rating")
private Double rating;
My Fragment
restRequest.getAllBooks().enqueue(new Callback<List<Books>>() {
@Override
public void onResponse(Response<List<Books>> response, Retrofit retrofit) {
//завершить наш прогресс диалог
if (response.isSuccess()) {
//Создаем коллекцию
List<Books> booksList = response.body();
realm = Realm.getDefaultInstance();
realm.beginTransaction();
List<Books> booking = realm.copyToRealm(booksList);
realm.commitTransaction();
booksAdapter.Pagination(booking);
}
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getContext(), "Error: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
and Retrofit
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(new OkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
//собрать
.build();
INSTANCE.boksAPI = retrofit.create(BoksAPI.class);
}
Please help,i dont know what it happen with my clases,but realm is work,cuz i see how memory grow up :O
Upvotes: 2
Views: 988
Reputation: 7010
I don't see that you configured Gson correctly. Somethere in your code should be similar initialization:
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
Look at the documentation for more details: https://realm.io/docs/java/latest/#gson
Upvotes: 1