Create Street
by this way:
Street
public class Street {
private List<StreetSegment> streetSegment;
public Street() {
// TODO Auto-generated constructor stub
}
public List<StreetSegment> getStreetSegment() {
return streetSegment;
}
public void setStreetSegment(List<StreetSegment> streetSegment) {
this.streetSegment = streetSegment;
}
}
StreetSegment
public class StreetSegment {
private String distance;
private String highway;
private String name;
private String line;
private String wayId;
public StreetSegment() {
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getHighway() {
return highway;
}
public void setHighway(String highway) {
this.highway = highway;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLine() {
return line;
}
public void setLine(String line) {
this.line = line;
}
public String getWayId() {
return wayId;
}
public void setWayId(String wayId) {
this.wayId = wayId;
}
}
To check it, here is main
:
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
String str = "{" +
" \"streetSegment\": [" +
" {" +
" \"distance\": \"0.04\"," +
" \"highway\": \"residential\"," +
" \"name\": \"Swift\"," +
" \"line\": \"-1.6720224 52.6251985,-1.6721061 52.6250432,-1.6721799, 52.6248908,-1.6721996 52.6247594\"," +
" \"wayId\": \"76473524\"" +
" }," +
" {" +
" \"distance\": \"0.05\"," +
" \"highway\": \"residential\"," +
" \"name\": \"Swift\"," +
" \"line\": \"-1.6721799 52.6248908,-1.6723374 52.6248669,-1.6732035 52.6249774,-1.6734643 52.6249894\"," +
" \"wayId\": \"76473523\"" +
" }" +
" ]" +
"}";
// to simulate stream reader
InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(str.getBytes()));
BufferedReader streamReader = new BufferedReader(in);
StringBuilder buff = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
buff.append(inputStr);
ObjectMapper mapper = new ObjectMapper();
Street mj = mapper.readValue(buff.toString(), Street.class);
if(mj == null){
System.err.println("null");
}
}
Checking...
System.out.println(mj.getStreetSegment().get(0).getHighway());//dummy print
Output: residential