Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserializing a custom class with Gson and Kinvey on Android
    text
    copied!<p>I am using the Kinvey Android SDK to retrieve data from their backend. It uses Gson behind the scenes. I have been unable to get it to deserialize an array of custom objects. Here is the entity definition and the JSON in question:</p> <pre><code>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() {} } </code></pre> <p>JSON body:</p> <pre><code>{ "_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" } } </code></pre> <p>If I change the <code>private Artifact[] artifacts</code> object to <code>private GenericJson[] artifacts</code>, the array is deserialized as an array of GenericJson objects, with the data fields intact in the Unknown Fields list. How can I get it to work for my custom object?</p> <p>Other things I have tried include <code>List&lt;Artifact&gt; artifacts</code> as well as ArrayList and Collection.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload