GsonObjectMapper implements ObjectMapper { @Override public <T> T readValue(String value, Class<T> valueType) { return om.fromJson(value, valueType); } GsonObjectMapper();  GsonObjectMapper(Gson om); @Override T readValue(String value, Class<T> valueType); @Override T readValue(String value, GenericType<T> genericType); @Override String writeValue(Object value);  }
@Test public void canRead(){ TestMe test = om.readValue("{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666}}", TestMe.class); assertEquals("foo", test.text); assertEquals(42, test.nmbr.intValue()); assertEquals("bar", test.another.text); assertEquals(666, test.another.nmbr.intValue()); assertEquals(null, test.another.another); }
@Test public void canReadGenerics(){ List<TestMe> testList = om.readValue("[{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666,\"another\":null}}]", new GenericType<List<TestMe>>(){}); TestMe test = testList.get(0); assertEquals("foo", test.text); assertEquals(42, test.nmbr.intValue()); assertEquals("bar", test.another.text); assertEquals(666, test.another.nmbr.intValue()); assertEquals(null, test.another.another); }