I have a bunch of JSON objects in a string notation:
"{\"address\":{\"street\":\"Steenstraat\",\"housenumber\":\"17A\",\"postalcode\":\"6828 CA\",\"city\":\"ARNHEM\",\"geoLocation\":{\"lat\":\"51.983718\",\"lng\":\"5.915553\"}},\"distance\":0,\"type\":\"ING\"}
So each of the JSON object looks something like this:
{
"address" : {
"street" : "Steenstraat",
"housnumber" : "17A",
"postalcode" : "6828 CA",
"city" : "ARNHEM",
"geolocation" : {
"latitude" : "51.983718",
"longitude" : "54.983718"
}
},
"type" : "citi",
"distance" : 0
}
Now, I used google's gson library to get from the rest API and that has given me a string of many of the above JSON objects. How can I try to filter out (or redefine the structure of the JSON) to sort the JSON objects by a particular parameter (say sort by city names)?
This is my Atm class. I'm trying to convert the JSON string to a list of Atm objects.
public class Atm {
private String type;
private Long distance;
private Map<String, String> address = new HashMap<String, String>();
public Atm() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getDistance() {
return distance;
}
public void setDistance(Long distance) {
this.distance = distance;
}
public Map<String, String> getAddress() {
return address;
}
public void setAddress(Map<String, String> address) {
this.address = address;
}
@Override
public String toString() {
return "Atm{" +
"type='" + type +
", distance=" + distance +
", address=" + address.toString() +
'}';
}
}
Or is there a way to do this without converting it into java data structures?