Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RealmList of String Type in Android

I'm using Realm for Local storage in Android. I'm getting 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'm getting this for ArrayList

Type parameter 'java.lang.String' is not within its bound; should extend 'io.realm.RealmObject'.

Thanks.

like image 433
user2566484 Avatar asked Feb 16 '16 12:02

user2566484


3 Answers

RealmLists doesn't support simple strings yet. so you have to wrap each String into its own object:

You can see a work-around here: Gson deserialization of List<String> into realmList<RealmString>

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

like image 194
Christian Melchior Avatar answered Nov 17 '22 08:11

Christian Melchior


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

Please refer to this pull request:

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

And the realm changelog:

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

like image 8
Yayo Arellano Avatar answered Nov 17 '22 06:11

Yayo Arellano


yes it is limitation from realm, you can't create array or list of strings, Please refer to the following link

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

like image 1
Hunain Avatar answered Nov 17 '22 06:11

Hunain