@Test public void testSerialize() throws Exception { String jsonBasic = JsonUtils.serialize(testResult); System.out.println(jsonBasic); Assert.assertTrue(!StringUtils.isEmpty(jsonBasic)); Throwable exceptionThrown = null; try {JsonUtils.serialize(null);} catch(Exception e) { exceptionThrown = e; } Assert.assertTrue(exceptionThrown != null); Assert.assertTrue(!StringUtils.isEmpty(exceptionThrown.getMessage())); Assert.assertTrue(exceptionThrown.getMessage().contains("cannot be converted")); new JsonUtils(); }
public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e) .addContextValue("object", jsonObject); } }
JsonUtils { public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e) .addContextValue("object", jsonObject); } } }
JsonUtils { public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e) .addContextValue("object", jsonObject); } }  }
JsonUtils { public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e) .addContextValue("object", jsonObject); } }  static String serialize(Object jsonObject); }
JsonUtils { public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e) .addContextValue("object", jsonObject); } }  static String serialize(Object jsonObject);  }