java - deserialize a json array using xstream -


there lot information @ stackoverflow how deserialize json array using gson.

but how can same using xstream jettison?

here json:

{"entity":[{"id":"1", "name":"aaa"}, {"id":"2", "name":"bbb"}]} 

here xstream code how try parse it:

xstream xstream = new xstream(new jettisonmappedxmldriver()); xstream.alias("entity", entity[].class); return (entity[])xstream.fromxml(jsonstring); 

i have following exception:

com.thoughtworks.xstream.converters.conversionexception: id : id 

with array cannot running, list:

java:

package de.mosst.spielwiese;  import java.io.inputstream; import java.util.arraylist; import java.util.list;  import org.junit.test;  import com.thoughtworks.xstream.xstream; import com.thoughtworks.xstream.annotations.xstreamalias; import com.thoughtworks.xstream.io.json.jettisonmappedxmldriver;  import lombok.data;  public class xstreamdeserializejsonwithjettison {      @test     @suppresswarnings("unchecked")     public void smoketest() {         inputstream file = xstreamdeserializejsonwithjettison.class.getresourceasstream("xstreamdeserializejsonwithjettison.json");         xstream xstream = new xstream(new jettisonmappedxmldriver());         xstream.processannotations(entity.class);          list<entity> entities = (list<entity>) xstream.fromxml(file);         system.out.println(entities);     }      @data     @lombok.allargsconstructor     @xstreamalias("entity")     class entity {         string id;         string name;     } } 

xml:

{     "list": [         {             "entity": [                 {                     "id": 1,                     "name": "odin"                 },                 {                     "id": 2,                     "name": "dwa"                 }             ]         }     ] } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -