I'm testing Jersey, I wanted to mack a mock endpoint that produces this JSON object
{
"Flight1" : 757,
"Flight2" : 107,
"Flight3" : 637,
}
so I've written written this resource:
@GET
@Path("myjson")
@Produces(MediaType.APPLICATION_JSON)
public String getMyJson(@QueryParam ("test1") String lat, @QueryParam("test2") String lng) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put("Flight 1", 765);
map.put("Flight 2", 657);
map.put("Flight 3", 908);
return map.toString();
}
But then I get this response when I call /myjson
{ Flight 1=765, Flight 2=657, Flight 3=908 }
Jersey already knows which element is a String and which element is an Integer, yet it format then as if they're all numbers. Also the Json as it stands can not be formatted by the "pretty" formatter, and I believe this makes parsing it difficult by http clients.
So my question are:
Why is this happening?
How to avoid it and write simple mock JSON object for testing that is correctly formatted