@Test public void test_withVisitor_noUnmapped() { String someJsonAllKnown = "{\"id\":42,\"name\":\"rob\",\"version\":1}"; CustReadVisitor custReadVisitor = new CustReadVisitor(); JsonReadOptions options = new JsonReadOptions(); options.addRootVisitor(custReadVisitor); Customer customer = Ebean.json().toBean(Customer.class, someJsonAllKnown, options); assertEquals(Integer.valueOf(42), customer.getId()); assertEquals("rob", customer.getName()); assertSame(customer, custReadVisitor.bean); assertNull(custReadVisitor.unmapped); }
@SuppressWarnings("unchecked") @Test public void test_unknownProperty_withVisitor() { String jsonWithUnknown = "{\"id\":42,\"unknownProp\":\"foo\",\"name\":\"rob\",\"version\":1,\"extraProp\":{\"name\":\"foobie\",\"sim\":\"bo\"}}"; CustReadVisitor custReadVisitor = new CustReadVisitor(); JsonReadOptions options = new JsonReadOptions(); options.addRootVisitor(custReadVisitor); Customer customer = Ebean.json().toBean(Customer.class, jsonWithUnknown, options); assertEquals(Integer.valueOf(42), customer.getId()); assertEquals("rob", customer.getName()); assertSame(customer, custReadVisitor.bean); assertEquals("foo", custReadVisitor.unmapped.get("unknownProp")); assertEquals(2, custReadVisitor.unmapped.size()); assertEquals( "foobie", ((Map<String, Object>) custReadVisitor.unmapped.get("extraProp")).get("name")); assertEquals( "bo", ((Map<String, Object>) custReadVisitor.unmapped.get("extraProp")).get("sim")); }