Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Android上的Gson和Kinvey反序列化自定义类_Java_Android_Gson_Kinvey - Fatal编程技术网

Java 使用Android上的Gson和Kinvey反序列化自定义类

Java 使用Android上的Gson和Kinvey反序列化自定义类,java,android,gson,kinvey,Java,Android,Gson,Kinvey,我正在使用Kinvey Android SDK从其后端检索数据。它在幕后使用Gson。我无法让它对自定义对象数组进行反序列化。以下是相关的实体定义和JSON: public class AlbumEntity extends GenericJson { @Key("_id") private String id; @Key private String name; @Key private String location_name;

我正在使用Kinvey Android SDK从其后端检索数据。它在幕后使用Gson。我无法让它对自定义对象数组进行反序列化。以下是相关的实体定义和JSON:

public class AlbumEntity extends GenericJson {
    @Key("_id")
    private String id;

    @Key
    private String name;

    @Key
    private String location_name;

    @Key
    private String start_date;

    @Key("artifacts")
    private Artifact[] artifacts;

    static class Artifact extends GenericJson { 
        @Key
        private String type;
        @Key
        private String photo_url;
        public Artifact() {}
    }

    @Key("_kmd")
    private KinveyMetaData meta; 

    public TripketEntity() {}
}
JSON正文:

{
"_id": "5216fec12f7b521a26064f9d",
"_kmd": {
    "ect": "2013-08-26T06:51:00.283Z",
    "lmt": "2013-09-05T15:28:28.079Z"
},
"artifacts": [
    {
        "type": "photo",
        "photo_url": "http://www.califliving.com/title24-energy/images/sanfrancisco.jpg"
    },
    {
        "type": "photo",
        "photo_url": "http://www.sanfrancisco.net/pictures/san-francisco.jpg"
    },
    {
        "type": "photo",
        "photo_url": "http://a2.cdn-hotels.com/images/themedcontent/en_GB/San%20Francisco_Top%2010.jpg"
    },
    {
        "type": "photo",
        "photo_url": "http://sanfranciscoforyou.com/wp-content/uploads/2010/03/san-francisco-city.jpg"
    }
],
"location_name": "San Francisco",
"name": "My Trip to the Bay",
"start_date": "06/15/2013",
"owner": {
    "_type": "KinveyRef",
    "_collection": "user",
    "_id": "5216fcd60b36c57d69000529"
},
"_acl": {
    "creator": "kid_ePPs9jXc_5"
}
}
如果我将
private Artifact[]artifacts
对象更改为
private GenericJson[]artifacts
,则数组将反序列化为GenericJson对象数组,数据字段在未知字段列表中保持不变。如何使其适用于我的自定义对象


我尝试过的其他东西包括
列出工件
以及ArrayList和Collection。

我是Kinvey的工程师,在Android库上工作-

在静态内部类的定义中添加一个
public
修饰符,GSON应该能够选择它:

...

@Key("artifacts") 
private Artifact[] artifacts;

public static class Artifact extends GenericJson {  
    @Key 
    private String type;
    @Key 
    private String photo_url;
    public Artifact() {} 
} 

@Key("_kmd") 
private KinveyMetaData meta;

... 

我是Kinvey的工程师,在安卓图书馆工作-

在静态内部类的定义中添加一个
public
修饰符,GSON应该能够选择它:

...

@Key("artifacts") 
private Artifact[] artifacts;

public static class Artifact extends GenericJson {  
    @Key 
    private String type;
    @Key 
    private String photo_url;
    public Artifact() {} 
} 

@Key("_kmd") 
private KinveyMetaData meta;

...