I have the json to retrieve below:
{
"name": "João",
"name": "Maria",
"name": "José"
}
I made this way:
ResponseEntity<List<Users>> responseEntityUsers = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Users.class);
But I got error.
My Users class is below:
public class Users {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
You need to design your JSON correctly, it is not well-formed JSON. It should be using an array of values for a specific attribute, like this:
{
“names”: [“João”, “Maria”, "José"]
}
Notice that I have propositionally changed the attribute name to "names". Which is a good practice when designing your JSON to transport your data. That change also will impact your Model class, that instead of String must have a String array:
public class Users {
private String[] names;
public String[] getNames() {
return names;
}
public void setNames(String[] names) {
this.names = names;
}
}
I wish you the best, cheers!
You need to design your JSON for this class:
[
{
"name":"João"
},{
"name":"Maria"
},{
"name":"José"
}
]
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.