assertEquals("Shmoe", jsonObject.get("last"));
assertEquals(100, jsonObject.get("age"));
}
public void testPOJOInteroperabilityJSON4JToJackson() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("first", "Joe");
jsonObject.put("last", "Shmoe");
jsonObject.put("age", 100);
ByteArrayOutputStream os = new ByteArrayOutputStream();
json4jObjectProvider.writeTo(jsonObject,
JSONObject.class,
JSONObject.class,
null,
MediaType.APPLICATION_JSON_TYPE,
null,
os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
PersonPOJO p =
(PersonPOJO)jacksonProvider.readFrom(Object.class,
PersonPOJO.class,
null,
MediaType.APPLICATION_JSON_TYPE,
null,
is);
assertEquals("Joe", p.getFirst());
assertEquals("Shmoe", p.getLast());
assertEquals(100, p.getAge());
jsonObject = new JSONObject();
jsonObject.put("first", "Joe");
jsonObject.put("last", "Shmoe");
jsonObject.put("age", "100"); // this is the only change to see if an
// integer as a String works
os = new ByteArrayOutputStream();
json4jObjectProvider.writeTo(jsonObject,
JSONObject.class,
JSONObject.class,