@Test public void shouldSerializeWorkerParameters() throws IOException { final WorkerParametersSerializer workerParametersSerializer = new WorkerParametersSerializer(); final WorkerParametersDeserializer workerParametersdeSerializer = new WorkerParametersDeserializer(); final DefaultWorkerParameters parameters = WorkerParametersFactory.newWorkerParameters(); final ObjectMapper mapper = new ObjectMapper(); for (final WorkerParameterName value : WorkerParameterName.values()) { parameters.putParameterValue(value, value.name()); } assertNotNull(parameters); final StringWriter stringJson = new StringWriter(); final JsonGenerator generator = new JsonFactory().createGenerator(stringJson); final SerializerProvider serializerProvider = mapper.getSerializerProvider(); workerParametersSerializer.serialize(parameters, generator, serializerProvider); generator.flush(); assertNotNull(stringJson.toString()); final InputStream stream = new ByteArrayInputStream(stringJson.toString().getBytes(StandardCharsets.UTF_8)); final JsonParser parser = mapper.getFactory().createParser(stream); final DeserializationContext ctxt = mapper.getDeserializationContext(); final DefaultWorkerParameters parametersDeser = (DefaultWorkerParameters) workerParametersdeSerializer.deserialize(parser, ctxt); assertTrue(parametersDeser.getContainerName().equals(parameters.getContainerName())); assertTrue(parametersDeser.getCurrentStep().equals(parameters.getCurrentStep())); assertTrue(parametersDeser.getMetadataRequest().equals(parameters.getMetadataRequest())); assertTrue(parametersDeser.getUrlMetadata().equals(parameters.getUrlMetadata())); assertTrue(parametersDeser.getUrlWorkspace().equals(parameters.getUrlWorkspace())); assertTrue(parametersDeser.getObjectId().equals(parameters.getObjectId())); assertTrue(parametersDeser.getObjectName().equals(parameters.getObjectName())); assertTrue(parametersDeser.getWorkerGUID().equals(parameters.getWorkerGUID())); assertTrue(parametersDeser.getProcessId().equals(parameters.getProcessId())); }
@Override public void serialize(AbstractWorkerParameters value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartObject(); for (final Entry<WorkerParameterName, String> item : value.getMapParameters().entrySet()) { gen.writeStringField(item.getKey().name(), item.getValue()); } gen.writeEndObject(); }
WorkerParametersSerializer extends JsonSerializer<AbstractWorkerParameters> { @Override public void serialize(AbstractWorkerParameters value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartObject(); for (final Entry<WorkerParameterName, String> item : value.getMapParameters().entrySet()) { gen.writeStringField(item.getKey().name(), item.getValue()); } gen.writeEndObject(); } }
WorkerParametersSerializer extends JsonSerializer<AbstractWorkerParameters> { @Override public void serialize(AbstractWorkerParameters value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartObject(); for (final Entry<WorkerParameterName, String> item : value.getMapParameters().entrySet()) { gen.writeStringField(item.getKey().name(), item.getValue()); } gen.writeEndObject(); } WorkerParametersSerializer(); }
WorkerParametersSerializer extends JsonSerializer<AbstractWorkerParameters> { @Override public void serialize(AbstractWorkerParameters value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartObject(); for (final Entry<WorkerParameterName, String> item : value.getMapParameters().entrySet()) { gen.writeStringField(item.getKey().name(), item.getValue()); } gen.writeEndObject(); } WorkerParametersSerializer(); @Override void serialize(AbstractWorkerParameters value, JsonGenerator gen,
        SerializerProvider serializers); }
WorkerParametersSerializer extends JsonSerializer<AbstractWorkerParameters> { @Override public void serialize(AbstractWorkerParameters value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartObject(); for (final Entry<WorkerParameterName, String> item : value.getMapParameters().entrySet()) { gen.writeStringField(item.getKey().name(), item.getValue()); } gen.writeEndObject(); } WorkerParametersSerializer(); @Override void serialize(AbstractWorkerParameters value, JsonGenerator gen,
        SerializerProvider serializers);  }