简体   繁体   English

Android中字符串类型的RealmList

[英]RealmList of String Type in Android

I'm using Realm for Local storage in Android. 我在Android中使用Realm进行本地存储。 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 而我正在为ArrayList得到这个

Type parameter 'java.lang.String' is not within its bound; 类型参数'java.lang.String'不在其范围内; should extend 'io.realm.RealmObject'. 应该扩展'io.realm.RealmObject'。

Thanks. 谢谢。

RealmLists doesn't support simple strings yet. RealmLists还不支持简单的字符串。 so you have to wrap each String into its own object: 所以你必须将每个String包装到它自己的对象中:

You can see a work-around here: Gson deserialization of List<String> into realmList<RealmString> 你可以在这里看到一个解决方法: 将List <String>的Gson反序列化为realmList <RealmString>

or here: https://realm.io/docs/java/latest/#primitive-lists 或者在这里: https//realm.io/docs/java/latest/#primitive-lists

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. Realm 4.0.0版将添加对RealmList的支持,它可以包含String,byte [],Boolean,Long,Integer,Short,Byte,Double,Float和Date值。

Please refer to this pull request: 请参阅此拉取请求:

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

And the realm changelog: 领域变更日志:

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

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 https://github.com/realm/realm-java/issues/575

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM