### Question:
JSONUtils { public static <T> T parseObject(String json, Class<T> clazz) { if (StringUtils.isEmpty(json)) { return null; } try { return objectMapper.readValue(json, clazz); } catch (Exception e) { logger.error("parse object exception!", e); } return null; } private  JSONUtils(); static ArrayNode createArrayNode(); static ObjectNode createObjectNode(); static JsonNode toJsonNode(Object obj); static String toJsonString(Object object, SerializationFeature feature); static T parseObject(String json, Class<T> clazz); static List<T> toList(String json, Class<T> clazz); static boolean checkJsonValid(String json); static String findValue(JsonNode jsonNode, String fieldName); static Map<String, String> toMap(String json); static Map<K, V> toMap(String json, Class<K> classK, Class<V> classV); static String toJsonString(Object object); static ObjectNode parseObject(String text); static ArrayNode parseArray(String text);  }### Answer:
@Test public void convert2Property() { Property property = new Property(); property.setProp("ds"); property.setDirect(Direct.IN); property.setType(DataType.VARCHAR); property.setValue("sssssss"); String str = "{\"direct\":\"IN\",\"prop\":\"ds\",\"type\":\"VARCHAR\",\"value\":\"sssssss\"}"; Property property1 = JSONUtils.parseObject(str, Property.class); Direct direct = property1.getDirect(); Assert.assertEquals(Direct.IN, direct); }
@Test public void testParseObject() { Assert.assertNull(JSONUtils.parseObject("")); Assert.assertNull(JSONUtils.parseObject("foo", String.class)); }
@Test public void parseObject() { String str = "{\"color\":\"yellow\",\"type\":\"renault\"}"; ObjectNode node = JSONUtils.parseObject(str); Assert.assertEquals("yellow", node.path("color").asText()); node.put("price", 100); Assert.assertEquals(100, node.path("price").asInt()); node.put("color", "red"); Assert.assertEquals("red", node.path("color").asText()); }
@Test public void jsonDataDeserializerTest() { String a = "{\"conditionResult\":\"{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]}\"," + "\"conditionsTask\":false,\"depList\":[],\"dependence\":\"{}\",\"forbidden\":false," + "\"id\":\"tasks-86823\",\"maxRetryTimes\":1,\"name\":\"shell test\"," + "\"params\":\"{\\\"resourceList\\\":[],\\\"localParams\\\":[],\\\"rawScript\\\":\\\"echo " + "'yyc'\\\"}\",\"preTasks\":\"[]\",\"retryInterval\":1,\"runFlag\":\"NORMAL\"," + "\"taskInstancePriority\":\"HIGHEST\",\"taskTimeoutParameter\":{\"enable\":false,\"interval\":0}," + "\"timeout\":\"{}\",\"type\":\"SHELL\",\"workerGroup\":\"default\"}"; TaskNode taskNode = JSONUtils.parseObject(a, TaskNode.class); Assert.assertTrue(true); }