android - How to read nested JSON arrays with Retrofit and Jackson? -
in android application use retrofit describe internal api:
@provides @singleton productsservice provideproductsservice() { objectmapper objectmapper = new objectmapper(); objectmapper.setpropertynamingstrategy( propertynamingstrategy.camel_case_to_lower_case_with_underscores); restadapter.builder restadapterbuilder = new restadapter.builder() .setconverter(new jacksonconverter(objectmapper)); return restadapterbuilder .setendpoint(endpoints.newfixedendpoint("http://192.168.1.1")) .build() .create(productsservice.class);
in order read productlevels created following interface:
public interface productsservice { @get("/api/products/{productid}/levels/") public observable<list<readproductlevelsresponse>> readproductlevels( @path("productid") int productid ); }
here json string served backend:
[ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ]
when try read json data in empty readproductlevelsresponse class following error occurs:
com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of readproductlevelsresponse out of start_array token @ [source: retrofit.exceptioncatchingtypedinput$exceptioncatchinginputstream@11ae0f16; line: 1, column: 2] (through reference chain: java.util.arraylist[0])
how can read json data readproductlevelsresponse class?
i figured out by answer have use list<list<double>>
response type.
public interface productsservice { @get("/api/products/{productid}/levels/") public observable<list<list<double>>> readproductlevels( @path("productid") int productid ); }
follow question: how transform nested list of double values java class using rxjava?
Comments
Post a Comment