From 86dbb450bc9232d7d94497aad996c87b47a3e478 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Thu, 11 Jan 2024 13:15:45 +0100 Subject: [PATCH] eBL: Avoid creating new ObjectMappers all the time Signed-off-by: Niels Thykier --- .../ebl/models/CarrierShippingInstructions.java | 3 +-- .../standards/ebl/party/CarrierScenarioParameters.java | 4 +++- .../standards/ebl/party/DynamicScenarioParameters.java | 8 ++++---- .../dcsa/conformance/standards/ebl/party/EblShipper.java | 9 +++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/models/CarrierShippingInstructions.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/models/CarrierShippingInstructions.java index 66bf7782..a4bfa164 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/models/CarrierShippingInstructions.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/models/CarrierShippingInstructions.java @@ -1,10 +1,10 @@ package org.dcsa.conformance.standards.ebl.models; +import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; import static org.dcsa.conformance.standards.ebl.party.ShippingInstructionsStatus.*; import static org.dcsa.conformance.standards.ebl.party.TransportDocumentStatus.*; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.time.LocalDate; @@ -16,7 +16,6 @@ import org.dcsa.conformance.standards.ebl.party.TransportDocumentStatus; public class CarrierShippingInstructions { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final Random RANDOM = new Random(); private static final String SI_STATUS = "shippingInstructionsStatus"; diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/CarrierScenarioParameters.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/CarrierScenarioParameters.java index db780327..a99b68e5 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/CarrierScenarioParameters.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/CarrierScenarioParameters.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import static org.dcsa.conformance.core.Util.STATE_OBJECT_MAPPER; + public record CarrierScenarioParameters( String carrierBookingReference, String commoditySubreference, @@ -15,7 +17,7 @@ public record CarrierScenarioParameters( String contractQuotationReference ) { public ObjectNode toJson() { - return new ObjectMapper() + return STATE_OBJECT_MAPPER .createObjectNode() .put("carrierBookingReference", carrierBookingReference()) .put("commoditySubreference", commoditySubreference()) diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java index 6316ccd4..97bd1a4b 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java @@ -1,14 +1,14 @@ package org.dcsa.conformance.standards.ebl.party; +import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; + import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import java.util.function.Function; import lombok.NonNull; import lombok.With; import org.dcsa.conformance.standards.ebl.checks.ScenarioType; -import java.util.function.Function; - @With public record DynamicScenarioParameters( @NonNull @@ -19,7 +19,7 @@ public record DynamicScenarioParameters( ShippingInstructionsStatus updatedShippingInstructionsStatus, TransportDocumentStatus transportDocumentStatus) { public ObjectNode toJson() { - return new ObjectMapper().createObjectNode() + return OBJECT_MAPPER.createObjectNode() .put("scenarioType", scenarioType.name()) .put("shippingInstructionsReference", shippingInstructionsReference) .put("transportDocumentReference", transportDocumentReference) diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblShipper.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblShipper.java index adc7be7a..8d5fc25a 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblShipper.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblShipper.java @@ -1,7 +1,8 @@ package org.dcsa.conformance.standards.ebl.party; +import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; + import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.*; @@ -155,7 +156,7 @@ private void cancelUpdateToShippingInstructions(JsonNode actionPrompt) { log.info("Shipper.cancelUpdateToShippingInstructions(%s)".formatted(actionPrompt.toPrettyString())); var documentReference = actionPrompt.required("documentReference").asText(); - var approvePayload = new ObjectMapper().createObjectNode() + var approvePayload = OBJECT_MAPPER.createObjectNode() .put("updatedShippingInstructionsStatus", ShippingInstructionsStatus.SI_UPDATE_CANCELLED.wireName()); syncCounterpartPatch( @@ -172,7 +173,7 @@ private void approveDraftTransportDocument(JsonNode actionPrompt) { log.info("Shipper.approveDraftTransportDocument(%s)".formatted(actionPrompt.toPrettyString())); var documentReference = actionPrompt.required("documentReference").asText(); - var approvePayload = new ObjectMapper().createObjectNode() + var approvePayload = OBJECT_MAPPER.createObjectNode() .put("transportDocumentStatus", TransportDocumentStatus.TD_APPROVED.wireName()); syncCounterpartPatch( @@ -217,7 +218,7 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { request.createResponse( 204, Map.of("Api-Version", List.of(apiVersion)), - new ConformanceMessageBody(new ObjectMapper().createObjectNode())); + new ConformanceMessageBody(OBJECT_MAPPER.createObjectNode())); addOperatorLogEntry( "Handled lightweight notification: %s".formatted(request.message().body().getJsonBody()));