I want to convert from JSon String
to Java
Object
and print it to the console. but it's not working:
here is the code:
try {
//From JSON String to Java-Object (Json encoding)
Person personObj = new Person();
JSONObject json2Java = new JSONObject("{\"id\":1,\"fullName\":\"name\",\"age\":22}");
personObj.setFullName(json2Java.getString("fullName"));
personObj.setAge(json2Java.getInt("age"));
personObj.setId(json2Java.getInt("id"));
System.out.println("Json2Java: " + personObj);
}
catch (JSONException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
.entity("Couldn't parse JSON string: " + e.getMessage())
.build());
}
this is what I get on the console:
Json2Java: com.akapoor.ws.testws.model.Person@86fe26
Can you tell me where my mistake is and what I have to change?