2013-09-05 3 views
1

나는 Kinvey Android SDK를 사용하여 백엔드에서 데이터를 검색합니다. 그 뒤에는 Gson이 사용됩니다. 나는 커스텀 객체 배열을 deserialize 할 수 없었다. 여기서 개체 정의와 해당 JSON이다Android에서 Gson과 Kinvey로 사용자 정의 클래스 비 직렬화

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 신체 : I가 private GenericJson[] artifactsprivate Artifact[] artifacts 객체를 변경하는 경우

{ 
"_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" 
} 
} 

어레이가 함께 GenericJson 객체 배열 역 직렬화 알 수없는 필드 목록에는 데이터 필드가 그대로 유지됩니다. 내 사용자 지정 개체에 대해 어떻게 작동시킬 수 있습니까?

내가 시도한 다른 것들은 List<Artifact> artifacts과 ArrayList 및 Collection을 포함합니다.

답변

1

나는 안드로이드 작업 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; 

...