Skip to content

Commit

Permalink
eBL: Avoid creating new ObjectMappers all the time
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Jan 15, 2024
1 parent 9d20cbb commit 86dbb45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 86dbb45

Please sign in to comment.