@Test public void testSerializeProcessor() throws IOException { final ObjectMapper jsonCodec = new ObjectMapper(); jsonCodec.registerModule(new JaxbAnnotationModule()); jsonCodec.setSerializationInclusion(Include.NON_NULL); final JsonEntitySerializer serializer = new JsonEntitySerializer(jsonCodec); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final ProcessorConfigDTO configDto = new ProcessorConfigDTO(); configDto.setProperties(Collections.singletonMap("key", "value")); final ProcessorDTO processorDto = new ProcessorDTO(); processorDto.setConfig(configDto); final ProcessorEntity processor = new ProcessorEntity(); processor.setId("123"); processor.setComponent(processorDto); serializer.serialize(processor, baos); final String serialized = new String(baos.toByteArray(), StandardCharsets.UTF_8); assertEquals("{\"id\":\"123\",\"component\":{\"config\":{\"properties\":{\"key\":\"value\"}}}}", serialized); } }
@Override public void serialize(final Object entity, final OutputStream out) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonGenerator generator = factory.createGenerator(out); generator.setCodec(jsonCodec); generator.writeObject(entity); generator.flush(); }
JsonEntitySerializer implements EntitySerializer { @Override public void serialize(final Object entity, final OutputStream out) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonGenerator generator = factory.createGenerator(out); generator.setCodec(jsonCodec); generator.writeObject(entity); generator.flush(); } }
JsonEntitySerializer implements EntitySerializer { @Override public void serialize(final Object entity, final OutputStream out) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonGenerator generator = factory.createGenerator(out); generator.setCodec(jsonCodec); generator.writeObject(entity); generator.flush(); } JsonEntitySerializer(final ObjectMapper jsonCodec); }
JsonEntitySerializer implements EntitySerializer { @Override public void serialize(final Object entity, final OutputStream out) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonGenerator generator = factory.createGenerator(out); generator.setCodec(jsonCodec); generator.writeObject(entity); generator.flush(); } JsonEntitySerializer(final ObjectMapper jsonCodec); @Override void serialize(final Object entity, final OutputStream out); }
JsonEntitySerializer implements EntitySerializer { @Override public void serialize(final Object entity, final OutputStream out) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonGenerator generator = factory.createGenerator(out); generator.setCodec(jsonCodec); generator.writeObject(entity); generator.flush(); } JsonEntitySerializer(final ObjectMapper jsonCodec); @Override void serialize(final Object entity, final OutputStream out);  }