@Test public void testGetObjectFromRef() { SampleObject sampleObject = new SampleObject().setId(OBJ_ID).setSubObject(new SampleObject().setId(SUB_ID)); SampleObject subObject = jsonHelper.getObjectFromRef(objectMapper.valueToTree(sampleObject), "/subObject", SampleObject.class); Assert.assertEquals(subObject.getId(), SUB_ID); }
public <T> T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz) { JsonNode jsonNode = rootNode.at(ref); if(jsonNode.isMissingNode()) return null; try { return objectMapper.treeToValue(jsonNode, clazz); } catch(JsonProcessingException e) { throw new JsonHelperException(String.format("Failed to map ref %1$s to object %2$s.", ref, clazz.getSimpleName()), e); } }
JsonHelper { public <T> T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz) { JsonNode jsonNode = rootNode.at(ref); if(jsonNode.isMissingNode()) return null; try { return objectMapper.treeToValue(jsonNode, clazz); } catch(JsonProcessingException e) { throw new JsonHelperException(String.format("Failed to map ref %1$s to object %2$s.", ref, clazz.getSimpleName()), e); } } }
JsonHelper { public <T> T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz) { JsonNode jsonNode = rootNode.at(ref); if(jsonNode.isMissingNode()) return null; try { return objectMapper.treeToValue(jsonNode, clazz); } catch(JsonProcessingException e) { throw new JsonHelperException(String.format("Failed to map ref %1$s to object %2$s.", ref, clazz.getSimpleName()), e); } } JsonHelper(); }
JsonHelper { public <T> T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz) { JsonNode jsonNode = rootNode.at(ref); if(jsonNode.isMissingNode()) return null; try { return objectMapper.treeToValue(jsonNode, clazz); } catch(JsonProcessingException e) { throw new JsonHelperException(String.format("Failed to map ref %1$s to object %2$s.", ref, clazz.getSimpleName()), e); } } JsonHelper(); T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz); Map<String, Object> getMapFromObject(Object object); T getObjectFromMap(Map<String, Object> map, Class<T> clazz); T getObjectFromString(String json, Class<T> clazz); String getJSONString(Object object); String getPrettyJSONString(Object object); void setNodeValue(JsonNode rootNode, String jsonPtrExpr, String value); ObjectMapper getObjectMapper(); }
JsonHelper { public <T> T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz) { JsonNode jsonNode = rootNode.at(ref); if(jsonNode.isMissingNode()) return null; try { return objectMapper.treeToValue(jsonNode, clazz); } catch(JsonProcessingException e) { throw new JsonHelperException(String.format("Failed to map ref %1$s to object %2$s.", ref, clazz.getSimpleName()), e); } } JsonHelper(); T getObjectFromRef(JsonNode rootNode, String ref, Class<T> clazz); Map<String, Object> getMapFromObject(Object object); T getObjectFromMap(Map<String, Object> map, Class<T> clazz); T getObjectFromString(String json, Class<T> clazz); String getJSONString(Object object); String getPrettyJSONString(Object object); void setNodeValue(JsonNode rootNode, String jsonPtrExpr, String value); ObjectMapper getObjectMapper();  }