RealmList of type String in Android

I am using Realm for local storage in Android. I get the following response form server.

[{ "ListId": 10, "Names": ["Name1", "Name2", "Name3", "Name4"] }] 

Here is my model

  public class Model extends RealmObject { private int ListId; private RealmList<String> Names = new RealmList<String>() public int getListId() { return ListId; } public void setListId(int listId) { ListId = listId; } public RealmList<String> getNames() { return Names; } public void setNames(RealmList<String> names) { Names = names; } } 

And I get it for ArrayList

A parameter of type "java.lang.String" is not within its bounds; should extend 'io.realm.RealmObject'.

Thanks.

+8
android realm
source share
3 answers

Realm version 4.0.0 will add support for RealmList, which can contain the values ​​String, byte [], Boolean, Long, Integer, Short, Byte, Double, Float and Date.

Please refer to this request:

https://github.com/realm/realm-java/pull/5031

And the change log in the area:

https://github.com/realm/realm-java/blob/master/CHANGELOG.md

+4
source share

RealmLists does not yet support simple strings. so you have to wrap each line in your own object:

Here you can see a workaround: Gson deserialization of list <String> to realmList <RealmString>

or here: https://realm.io/docs/java/latest/#primitive-lists

+11
source share

yes, this is a restriction from scope, you cannot create an array or a list of strings, please refer to the following link

https://github.com/realm/realm-java/issues/575

+1
source share

All Articles