JSONTool { public Object fromString(String str) { if (StringUtils.isNotBlank(str)) { ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.readValue(str, Object.class); } catch (Exception e) { LOGGER.info("Failed to parse JSON [{}]: {}", StringUtils.abbreviate(str, 32), ExceptionUtils.getRootCauseMessage(e)); return null; } } return null; }  String serialize(Object object); Object fromString(String str); @Deprecated JSON parse(String json);  }
@Test void fromStringArray() { assertEquals(Arrays.asList(1, 2, 3), this.tool.fromString("[1,2,3]")); }
@Test void fromStringEmptyArray() { assertEquals(new ArrayList<>(), this.tool.fromString("[]")); }
@Test void fromStringMap() { Map<?, ?> map = (Map) this.tool.fromString("{\"a\" : 1, \"b\": [1], \"c\": true}"); assertEquals(3, map.size()); assertEquals(1, map.get("a")); assertEquals(Arrays.asList(1), map.get("b")); assertEquals(true, map.get("c")); }
@Test void fromStringEmptyMap() { assertEquals(new HashMap(), this.tool.fromString("{}")); }
@Test void fromStringNull() { assertNull(this.tool.fromString(null)); }
@Test void fromStringEmptyString() { assertNull(this.tool.fromString("")); }
@Test void fromStringInvalidJSON() { assertNull(this.tool.fromString("This is not the JSON you are looking for...")); }