/** Can we handle a more complex Javabean? */ @Test public void complexJavabean() throws JSONException { UserWithPhotos userWithPhotos = new UserWithPhotos(); userWithPhotos.uid = 12345L; userWithPhotos.name = null; userWithPhotos.photos = new ArrayList<Photo>(); userWithPhotos.photos.add(new Photo()); Photo photo = new Photo(); photo.photoId = 5678L; photo.location = "Las Vegas"; userWithPhotos.photos.add(photo); String json = createJsonMapper().toJson(userWithPhotos); String expectedJson = "{\"uid\":12345,\"photos\":[{\"id\":null,\"location\":null},{\"id\":5678,\"location\":\"Las Vegas\"}],\"name\":null}"; JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.NON_EXTENSIBLE); }