@Test public void testToObjectNode() throws JsonUtilsException { ObjectNode on = JsonUtils.toObjectNode("{\"key\":\"value\"}"); assertEquals("{\"key\":\"value\"}", on.toString()); ObjectNode ovdf = JsonUtils.toObjectNode(OVDF); String expectedOvdf = "{\"className\":\"com.bah.ode.model.OdeVehicleDataFlat\",\"serialId\":\"10817812-036b-4d7b-867b-ae0bc62a2b3e.0\",\"receivedAt\":\"2015-07-22T19:21:16.413+0000\",\"groupId\":\"4130008F\",\"accelLong\":0.34,\"accelVert\":0.0,\"accellYaw\":8.42,\"heading\":65.95,\"speed\":8.12,\"sizeLength\":500,\"sizeWidth\":200,\"latitude\":42.3296667,\"longitude\":-83.044539,\"elevation\":156.9,\"tempId\":\"C4290123\",\"year\":2015,\"month\":5,\"day\":13,\"hour\":15,\"minute\":52,\"second\":45.5,\"dateTime\":\"2015-06-13T19:52:45.500+0000\"}"; assertEquals(expectedOvdf, ovdf.toString()); JsonUtils.addNode(ovdf, "avgSpeed", "2.22"); assertEquals( "{\"className\":\"com.bah.ode.model.OdeVehicleDataFlat\",\"serialId\":\"10817812-036b-4d7b-867b-ae0bc62a2b3e.0\",\"receivedAt\":\"2015-07-22T19:21:16.413+0000\",\"groupId\":\"4130008F\",\"accelLong\":0.34,\"accelVert\":0.0,\"accellYaw\":8.42,\"heading\":65.95,\"speed\":8.12,\"sizeLength\":500,\"sizeWidth\":200,\"latitude\":42.3296667,\"longitude\":-83.044539,\"elevation\":156.9,\"tempId\":\"C4290123\",\"year\":2015,\"month\":5,\"day\":13,\"hour\":15,\"minute\":52,\"second\":45.5,\"dateTime\":\"2015-06-13T19:52:45.500+0000\",\"avgSpeed\":2.22}", ovdf.toString()); }
public static ObjectNode toObjectNode(String tree) throws JsonUtilsException { ObjectNode jsonNode; try { jsonNode = (ObjectNode) mapper.readTree(tree); } catch (Exception e) { throw new JsonUtilsException("Error converting JSON tree to ObjectNode", e); } return jsonNode; }
JsonUtils { public static ObjectNode toObjectNode(String tree) throws JsonUtilsException { ObjectNode jsonNode; try { jsonNode = (ObjectNode) mapper.readTree(tree); } catch (Exception e) { throw new JsonUtilsException("Error converting JSON tree to ObjectNode", e); } return jsonNode; } }
JsonUtils { public static ObjectNode toObjectNode(String tree) throws JsonUtilsException { ObjectNode jsonNode; try { jsonNode = (ObjectNode) mapper.readTree(tree); } catch (Exception e) { throw new JsonUtilsException("Error converting JSON tree to ObjectNode", e); } return jsonNode; } private  JsonUtils(); }
JsonUtils { public static ObjectNode toObjectNode(String tree) throws JsonUtilsException { ObjectNode jsonNode; try { jsonNode = (ObjectNode) mapper.readTree(tree); } catch (Exception e) { throw new JsonUtilsException("Error converting JSON tree to ObjectNode", e); } return jsonNode; } private  JsonUtils(); static String toJson(Object o, boolean verbose); static Object fromJson(String s, Class<?> clazz); static Object jacksonFromJson(String s, Class<?> clazz); static String newJson(String key, Object value); static ObjectNode cloneObjectNode(ObjectNode src); static ObjectNode newObjectNode(String key, Object value); static ObjectNode addNode(ObjectNode tree, String fieldName, Object fieldValue); static JsonNode getJsonNode(String tree, String fieldName); static ObjectNode newNode(); static ArrayNode newArrayNode(); static ObjectNode toObjectNode(String tree); static JSONObject toJSONObject(String json); static boolean isValid(String tree); static HashMap<String, JsonNode> jsonNodeToHashMap(JsonNode jsonNode); static String jsonKeyValue(String key, String value); static BigDecimal decimalValue(JsonNode v); }
JsonUtils { public static ObjectNode toObjectNode(String tree) throws JsonUtilsException { ObjectNode jsonNode; try { jsonNode = (ObjectNode) mapper.readTree(tree); } catch (Exception e) { throw new JsonUtilsException("Error converting JSON tree to ObjectNode", e); } return jsonNode; } private  JsonUtils(); static String toJson(Object o, boolean verbose); static Object fromJson(String s, Class<?> clazz); static Object jacksonFromJson(String s, Class<?> clazz); static String newJson(String key, Object value); static ObjectNode cloneObjectNode(ObjectNode src); static ObjectNode newObjectNode(String key, Object value); static ObjectNode addNode(ObjectNode tree, String fieldName, Object fieldValue); static JsonNode getJsonNode(String tree, String fieldName); static ObjectNode newNode(); static ArrayNode newArrayNode(); static ObjectNode toObjectNode(String tree); static JSONObject toJSONObject(String json); static boolean isValid(String tree); static HashMap<String, JsonNode> jsonNodeToHashMap(JsonNode jsonNode); static String jsonKeyValue(String key, String value); static BigDecimal decimalValue(JsonNode v);  }