ToJsonSerializer { public String objectToJson(Object object) { JacksonSerializationEngine engine = new JacksonSerializationEngine(); engine.init(null); try { return engine.serialize(object); } catch (Exception e) { System.out.println(e); } return ""; }  String objectToJson(Object object);  }
@Test public void shouldSerializePerson() throws Exception { Person person = new Person(); String serializedString = toJsonSerializer.objectToJson(person); assertThat(serializedString).isEqualTo("{\"name\":\"john\",\"age\":12}"); }
@Test public void shouldSerializeBristleMessageWithPerson() throws Exception { BristleMessage bristleMessage = new BristleMessage(); bristleMessage.withId("123"); bristleMessage.withName("name"); bristleMessage.withPayload(new Person()); String serializedString = toJsonSerializer.objectToJson(bristleMessage); assertThat(serializedString).isEqualTo("{\"id\":\"123\",\"name\":\"name\",\"payload\":{\"name\":\"john\",\"age\":12}}"); }