ProjectedResultMapper { public <R> R mapTo(Class<R> resultClass, Object properties, String[] propertyNames) { return propertyNames.length == 1 ? resultClass.cast(properties) : mapper.convertValue(propertyMap((Object[]) properties, propertyNames), resultClass); } ProjectedResultMapper(ObjectMapper mapper);  ProjectedResultMapper(); R mapTo(Class<R> resultClass, Object properties,
            String[] propertyNames);  }
@Test public void mapTo_Simple() { SimpleClass s1 = new SimpleClass(100, "test name"); String[] props = props("id", "name", "created"); Object[] vals = vals(s1.getId(), s1.getName(), s1.getCreated()); SimpleClass s2 = mapper.mapTo(SimpleClass.class, vals, props); assertEquals(s1, s2); }
@Test(expected = IllegalArgumentException.class) public void mapTo_Simple_notEnoughPropertyNames() { String[] props = props("id", "not enough property names"); Object[] vals = vals(s1.getId(), s1.getName(), s1.getCreated()); mapper.mapTo(SimpleClass.class, vals, props); }
@Test(expected = IllegalArgumentException.class) public void mapTo_Simple_tooManyPropertyNames() { String[] props = props("id", "too", "many", "property", "names"); Object[] vals = vals(s1.getId(), s1.getName(), s1.getCreated()); mapper.mapTo(SimpleClass.class, vals, props); }
@Test(expected = IllegalArgumentException.class) public void mapTo_Simple_badPropertyNames() { String[] props = props("id", "bad", "names"); Object[] vals = vals(s1.getId(), s1.getName(), s1.getCreated()); mapper.mapTo(SimpleClass.class, vals, props); }
@Test public void mapTo_Integer() { Integer one = 1; assertEquals(one, mapper.mapTo(Integer.class, one, props("id"))); }
@Test(expected = ClassCastException.class) public void mapTo_Integer_ClassCastException() { mapper.mapTo(Integer.class, vals("not a number"), props("id")); }
@Test public void mapTo_String() { String testString = "test string"; assertEquals(testString, mapper.mapTo(String.class, testString, props("name"))); }