@Test public void fromJSON_correct_json_with_double_quotes_results_in_expected_object() throws Exception { String json = "{\"info\":\"test1\"}"; JSONConverterTestObject result = converterToTest.fromJSON(JSONConverterTestObject.class, json); assertEquals("test1", result.getInfo()); }
public <T> T fromJSON(Class<T> clazz, String jSON) throws JSONConverterException { if (clazz == null) { throw new IllegalStateException("clazz may not be null!"); } String string = jSON; if (jSON == null) { string = ""; } try { byte[] bytes = string.getBytes(); return mapper.readValue(bytes, clazz); } catch (IOException e) { LOG.debug("JSON conversion failed, origin JSON:\n{}", jSON); String truncatedJSON = SimpleStringUtils.truncateWhenTooLong(jSON, 300); throw new JSONConverterException("Was not able to convert JSON string to " + clazz + " object\nContent was:\n" + truncatedJSON, e); } }
JSONConverter { public <T> T fromJSON(Class<T> clazz, String jSON) throws JSONConverterException { if (clazz == null) { throw new IllegalStateException("clazz may not be null!"); } String string = jSON; if (jSON == null) { string = ""; } try { byte[] bytes = string.getBytes(); return mapper.readValue(bytes, clazz); } catch (IOException e) { LOG.debug("JSON conversion failed, origin JSON:\n{}", jSON); String truncatedJSON = SimpleStringUtils.truncateWhenTooLong(jSON, 300); throw new JSONConverterException("Was not able to convert JSON string to " + clazz + " object\nContent was:\n" + truncatedJSON, e); } } }
JSONConverter { public <T> T fromJSON(Class<T> clazz, String jSON) throws JSONConverterException { if (clazz == null) { throw new IllegalStateException("clazz may not be null!"); } String string = jSON; if (jSON == null) { string = ""; } try { byte[] bytes = string.getBytes(); return mapper.readValue(bytes, clazz); } catch (IOException e) { LOG.debug("JSON conversion failed, origin JSON:\n{}", jSON); String truncatedJSON = SimpleStringUtils.truncateWhenTooLong(jSON, 300); throw new JSONConverterException("Was not able to convert JSON string to " + clazz + " object\nContent was:\n" + truncatedJSON, e); } } JSONConverter(); }
JSONConverter { public <T> T fromJSON(Class<T> clazz, String jSON) throws JSONConverterException { if (clazz == null) { throw new IllegalStateException("clazz may not be null!"); } String string = jSON; if (jSON == null) { string = ""; } try { byte[] bytes = string.getBytes(); return mapper.readValue(bytes, clazz); } catch (IOException e) { LOG.debug("JSON conversion failed, origin JSON:\n{}", jSON); String truncatedJSON = SimpleStringUtils.truncateWhenTooLong(jSON, 300); throw new JSONConverterException("Was not able to convert JSON string to " + clazz + " object\nContent was:\n" + truncatedJSON, e); } } JSONConverter(); static JSONConverter get(); String toJSON(Object object); String toJSON(Object object, boolean prettyPrinted); T fromJSON(Class<T> clazz, String jSON); }
JSONConverter { public <T> T fromJSON(Class<T> clazz, String jSON) throws JSONConverterException { if (clazz == null) { throw new IllegalStateException("clazz may not be null!"); } String string = jSON; if (jSON == null) { string = ""; } try { byte[] bytes = string.getBytes(); return mapper.readValue(bytes, clazz); } catch (IOException e) { LOG.debug("JSON conversion failed, origin JSON:\n{}", jSON); String truncatedJSON = SimpleStringUtils.truncateWhenTooLong(jSON, 300); throw new JSONConverterException("Was not able to convert JSON string to " + clazz + " object\nContent was:\n" + truncatedJSON, e); } } JSONConverter(); static JSONConverter get(); String toJSON(Object object); String toJSON(Object object, boolean prettyPrinted); T fromJSON(Class<T> clazz, String jSON);  }