简体   繁体   中英

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

We need to change the type of 'data' from

List<Map<Integer, Array>>

to

List<List<String>>

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

private List<ArrayList<String>> data;

Worked like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM