javaarraysrestdictionaryspring-android

Java - unable to map JSON array to object with Spring getForObject()


I have to consume an API RESTful web service. At the moment I have to deal with a JSON object which looks like:

{
  "success":true,
  "error":"",
  "message":"",
  "data":[
     ["USD","US Dollar","11,696", "connected"],
     ["EUR","Euro","10,733","connected"]
  ]
}

And this is the class I use in general to hold most endpoints of this web service:

public class Response {
    public boolean success;
    private String error;
    private String message;        
    private List<Map<Integer, Array>> data;

    public String getError() {
        return this.error;
    }

    public String getMessage() {
        return this.message;
    }

    public Map<Integer,Array> getData() {
        return this.data.get(0);
    }
}

When running, app crashes with:

Could not read JSON: Can not deserialize instance of java.util.LinkedHashMap 
     out of START_ARRAY token

Solution

  • I ended up figuring out that what i need is just:

    private List<ArrayList<String>> data;
    

    Worked like a charm.