### Question:
JSONUtils { public static Map<String, String> toMap(String json) { if (StringUtils.isEmpty(json)) { return null; } try { return objectMapper.readValue(json, new TypeReference<Map<String, String>>() { }); } catch (Exception e) { logger.error("json to map 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 toMap() { String jsonStr = "{\"id\":\"1001\",\"name\":\"Jobs\"}"; Map<String, String> models = JSONUtils.toMap(jsonStr); Assert.assertEquals("1001", models.get("id")); Assert.assertEquals("Jobs", models.get("name")); }
@Test public void testToMap() { Map<String, String> map = new HashMap<>(); map.put("foo", "bar"); Assert.assertTrue(map.equals(JSONUtils.toMap( "{\n" + "\"foo\": \"bar\"\n" + "}"))); Assert.assertFalse(map.equals(JSONUtils.toMap( "{\n" + "\"bar\": \"foo\"\n" + "}"))); Assert.assertNull(JSONUtils.toMap("3")); Assert.assertNull(JSONUtils.toMap(null)); Assert.assertNull(JSONUtils.toMap("3", null, null)); Assert.assertNull(JSONUtils.toMap(null, null, null)); String str = "{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}"; Map<String, String> m = JSONUtils.toMap(str); Assert.assertNotNull(m); }