@Test public void shouldGenerateFromList() { deleteAndPopulateTables("users", "addresses"); LazyList<User> personList = User.findAll().orderBy("id").include(Address.class); String json = personList.toJson(false); JsonHelper.readTree(json); // validate }
@Test public void shouldIncludeUglyChildren() { deleteAndPopulateTables("users", "addresses"); List<User> personList = User.findAll().orderBy("id").include(Address.class); User u = personList.get(0); String json = u.toJson(false); Map m = JsonHelper.toMap(json); a(m.get("first_name")).shouldBeEqual("Marilyn"); a(m.get("last_name")).shouldBeEqual("Monroe"); Map children = (Map) m.get("children"); List<Map> addresses = (List<Map>) children.get("addresses"); the(addresses.size()).shouldBeEqual(3); // at this point, no need to verify, since the order of addresses is not guaranteed.. or is it?? }