android - Jackson + Gson + Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY -
i know has been asked lot but, none of question i've found solve especific problem.
here json
[json url][1]
[ { "unit":"imeca", "value":29, }, { "unit":"imeca", "value":43, } ] this dto
zona.java
public class zona { private string unit; private int value; public string getunit() { return unit; } public void setunit(string unit) { this.unit = unit; } public int getvalue() { return value; } public void setvalue(int value) { this.value = value; } @override public string tostring() { return string.valueof(unit) + ": " + string.valueof(value); } } and interface
api.java
public interface api { @get("/data/heatmap_stations.json") call<zona> getzona(); } i kind of understand why happens , because json array response jackson + gson expecting single json object.
i tried creating pojo this:
zonas.java
public class zonas extends arraylist<zona> {} and changing call signature in interface , retrofit call, replacing single dto plural, (from call< zona > call< zonas >, replacing single class 1 inherits arraylist<>), nothing, mean, didn't threw exception, didn't threw response either.
change
public interface api { @get("/data/heatmap_stations.json") call<zona> getzona(); } to
public interface api { @get("/data/heatmap_stations.json") call<list<zona>> getzona(); } you telling expect single zona object returning array of zona objects
Comments
Post a Comment