### Question:
LazyJson implements Serializable { public T get() { if (object == null && json == null) { return null; } if (object == null) { object = (T) JsonUtils.from(Yawp.yawp(), json, type); } return object; }  static LazyJson<T> create(T object); void set(T value); T get(); String getJson(); boolean isJsonArray(); static LazyJson<?> create(Type type, String json); boolean isParsed();  }### Answer:
@Test public void testAsListProperty() { BasicObject object = new BasicObject(); object.setLazyListPojo(Arrays.asList(new Pojo("xpto1"), new Pojo("xpto2"))); String json = JsonUtils.to(object); BasicObject parsedObject = JsonUtils.from(yawp, json, BasicObject.class); json = JsonUtils.to(parsedObject); parsedObject = JsonUtils.from(yawp, json, BasicObject.class); List<Pojo> lazyListPojo = parsedObject.getLazyListPojo(); assertEquals("xpto1", lazyListPojo.get(0).getStringValue()); assertEquals("xpto2", lazyListPojo.get(1).getStringValue()); }
@Test public void testAsMapProperty() { BasicObject object = new BasicObject(); object.setLazyMapPojo(createPojoMap()); String json = JsonUtils.to(object); BasicObject parsedObject = JsonUtils.from(yawp, json, BasicObject.class); json = JsonUtils.to(parsedObject); parsedObject = JsonUtils.from(yawp, json, BasicObject.class); assertEquals("xpto", parsedObject.getLazyMapPojo().get(1l).getStringValue()); }
@Test public void testAsMapWithLazyListProperty() { BasicObject object = new BasicObject(); object.setMapLazyPojoList(createMapWithLazyList()); String json = JsonUtils.to(object); BasicObject parsedObject = JsonUtils.from(yawp, json, BasicObject.class); json = JsonUtils.to(parsedObject); parsedObject = JsonUtils.from(yawp, json, BasicObject.class); List<Pojo> list = parsedObject.getMapLazyPojoList().get("xpto").get(); assertEquals(2, list.size()); assertEquals("otpx", list.get(0).getStringValue()); assertEquals("xpto", list.get(1).getStringValue()); }
@Test public void testAsIdRefMapProperty() { BasicObject object = new BasicObject(); object.setLazyIdRefMapPojo(createPojoIdRefMap()); String json = JsonUtils.to(object); BasicObject parsedObject = JsonUtils.from(yawp, json, BasicObject.class); json = JsonUtils.to(parsedObject); parsedObject = JsonUtils.from(yawp, json, BasicObject.class); assertEquals("xpto", parsedObject.getLazyIdRefMapPojo().get(id(BasicObject.class, 1l)).getStringValue()); }
@Test public void testSaveAndLoad() { BasicObject object = new BasicObject(); object.setLazyPojo(new Pojo("xpto")); object.setLazyListPojo(Arrays.asList(new Pojo("xpto"))); object.setLazyMapPojo(createPojoMap()); object.setLazyIdRefMapPojo(createPojoIdRefMap()); yawp.save(object); BasicObject retrievedObject = object.getId().fetch(); assertEquals("xpto", retrievedObject.getLazyPojo().getStringValue()); assertEquals("xpto", retrievedObject.getLazyListPojo().get(0).getStringValue()); assertEquals("xpto", retrievedObject.getLazyMapPojo().get(1l).getStringValue()); assertEquals("xpto", retrievedObject.getLazyIdRefMapPojo().get(id(BasicObject.class, 1l)).getStringValue()); }