diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/AttachableResponseDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/AttachableResponseDeserializer.java index 015029be..bd260396 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/AttachableResponseDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/AttachableResponseDeserializer.java @@ -43,21 +43,24 @@ public class AttachableResponseDeserializer extends JsonDeserializer */ private static final String OPTIONS_DATA = "optionsData"; + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ + @SuppressWarnings("deprecation") + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); + AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); + mapper.setSerializationInclusion(Include.NON_NULL); + } + @Override public void serialize(BatchItemRequest batchItemRequest, JsonGenerator jgen, SerializerProvider provider) throws IOException { @@ -161,14 +172,6 @@ private String getCDCQueryJson(CDCQuery cdcQuery) throws SerializationException * @return ObjectMapper the object mapper */ private ObjectMapper getObjectMapper() { - ObjectMapper mapper = new ObjectMapper(); - AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - - mapper.setAnnotationIntrospector(pair); - mapper.setSerializationInclusion(Include.NON_NULL); - return mapper; } diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/BatchItemResponseDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/BatchItemResponseDeserializer.java index 2e05d841..cc356e77 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/BatchItemResponseDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/BatchItemResponseDeserializer.java @@ -83,20 +83,23 @@ public class BatchItemResponseDeserializer extends JsonDeserializer * variable QUERY_RESPONSE */ private static final String QUERY_RESPONSE = "QueryResponse"; - + + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ @SuppressWarnings("deprecation") - @Override - public CDCResponse deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS,true); - //Make the mapper JAXB annotations aware + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @Override + public CDCResponse deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { //Read the QueryResponse as a tree JsonNode jn = jp.readValueAsTree(); diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/CustomFieldDefinitionDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/CustomFieldDefinitionDeserializer.java index f432b0e0..210e4f63 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/CustomFieldDefinitionDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/CustomFieldDefinitionDeserializer.java @@ -50,18 +50,21 @@ public class CustomFieldDefinitionDeserializer extends JsonDeserializer */ private ObjectFactory objFactory = new ObjectFactory(); + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ + @SuppressWarnings("deprecation") + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); + AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); + AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + /** * {@inheritDoc}} */ - @SuppressWarnings("deprecation") @Override public IntuitResponse deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { - ObjectMapper mapper = new ObjectMapper(); Report report = new Report(); - mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS,true); - //Make the mapper JAXB annotations aware - AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); - AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); - - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //Read the QueryResponse as a tree diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/JSONSerializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/JSONSerializer.java index dfa9798f..8153946c 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/JSONSerializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/JSONSerializer.java @@ -234,6 +234,31 @@ public class JSONSerializer implements IEntitySerializer { */ private static final org.slf4j.Logger LOG = Logger.getLogger(); + /** Shared ObjectMapper for serialization (thread-safe, reuse for performance) */ + @SuppressWarnings("deprecation") + private static final ObjectMapper serializeMapper; + static { + serializeMapper = new ObjectMapper(); + AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); + AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(serializeMapper.getTypeFactory()); + serializeMapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); + serializeMapper.setSerializationInclusion(Include.NON_NULL); + } + + /** Shared ObjectMapper for deserialization (thread-safe, reuse for performance) */ + private static final ObjectMapper deserializeMapper; + static { + deserializeMapper = new ObjectMapper(); + deserializeMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); + SimpleModule simpleModule = new SimpleModule("IntuitResponseDeserializer", new Version(1, 0, 0, null)); + simpleModule.addDeserializer(IntuitResponse.class, new IntuitResponseDeserializer()); + deserializeMapper.registerModule(simpleModule); + simpleModule = new SimpleModule("TaxServiceDeserializer", new Version(1, 0, 0, null)); + simpleModule.addDeserializer(TaxService.class, new TaxServiceDeserializer()); + deserializeMapper.registerModule(simpleModule); + deserializeMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + /** * {@inheritDoc} */ @@ -244,14 +269,7 @@ public String serialize(T object) throws SerializationException { return null; } - ObjectMapper mapper = new ObjectMapper(); - AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - - mapper.setAnnotationIntrospector(pair); - mapper.setSerializationInclusion(Include.NON_NULL); - + ObjectMapper mapper = serializeMapper.copy(); registerModulesForEnum(mapper); SimpleModule testModule = new SimpleModule("BatchItemRequest", new Version(1, 0, 0, null)); @@ -285,16 +303,7 @@ public String serialize(T object) throws SerializationException { public Response deserialize(String json, Class cl) throws SerializationException { Response intuitResponse = null; - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS,true); - SimpleModule simpleModule = new SimpleModule("IntuitResponseDeserializer", new Version(1, 0, 0, null)); - simpleModule.addDeserializer(IntuitResponse.class, new IntuitResponseDeserializer()); - mapper.registerModule(simpleModule); - - simpleModule = new SimpleModule("TaxServiceDeserializer", new Version(1, 0, 0, null)); - simpleModule.addDeserializer(TaxService.class, new TaxServiceDeserializer()); - mapper.registerModule(simpleModule); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ObjectMapper mapper = deserializeMapper; diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/QueryResponseDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/QueryResponseDeserializer.java index 60f46556..251f9005 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/QueryResponseDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/QueryResponseDeserializer.java @@ -77,17 +77,20 @@ public class QueryResponseDeserializer extends JsonDeserializer { */ private ObjectFactory objFactory = new ObjectFactory(); + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ @SuppressWarnings("deprecation") - @Override - public QueryResponse deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS,true); - //Make the mapper JAXB annotations aware + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @Override + public QueryResponse deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { //Read the QueryResponse as a tree JsonNode jn = jp.readValueAsTree(); diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorDeserializer.java index 79bc4470..58001bb6 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorDeserializer.java @@ -44,8 +44,17 @@ import com.intuit.ipp.util.Logger; public class SyncErrorDeserializer extends JsonDeserializer { - - ObjectMapper mapper = new ObjectMapper(); + + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ + @SuppressWarnings("deprecation") + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); + AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } /** * logger instance @@ -74,17 +83,8 @@ public class SyncErrorDeserializer extends JsonDeserializer { */ private ObjectFactory objFactory = new ObjectFactory(); - @SuppressWarnings("deprecation") @Override public SyncError deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { - - - //Make the mapper JAXB annotations aware - AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); - AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //Read the QueryResponse as a tree JsonNode jn = jp.readValueAsTree(); diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorResponseDeserializer.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorResponseDeserializer.java index b45b929d..7b94b1d5 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorResponseDeserializer.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/serialization/SyncErrorResponseDeserializer.java @@ -70,20 +70,20 @@ public class SyncErrorResponseDeserializer extends JsonDeserializer{ * variable FAULT */ private static final String FAULT = "Fault"; - - - + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ + @SuppressWarnings("deprecation") + private static final ObjectMapper mapper; + static { + mapper = new ObjectMapper(); + AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); + AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); + mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(primary, secondary)); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + /** * {@inheritDoc}} */ - @SuppressWarnings("deprecation") @Override public TaxService deserialize(JsonParser jp, DeserializationContext desContext) throws IOException { - - ObjectMapper mapper = new ObjectMapper(); TaxService taxService = new TaxService(); - - //Make the mapper JAXB annotations aware - AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); - AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); - - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //mapper.setPropertyNamingStrategy(PascalCaseStrategy); @@ -119,17 +116,6 @@ public TaxService deserialize(JsonParser jp, DeserializationContext desContext) private TaxRateDetails getTaxRateDetails(JsonNode jn) throws IOException { TaxRateDetails taxRateDetails = new TaxRateDetails(); - - ObjectMapper mapper = new ObjectMapper(); - - //Make the mapper JAXB annotations aware - AnnotationIntrospector primary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); - AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); - mapper.setAnnotationIntrospector(pair); - - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Iterator ite = jn.fieldNames(); while (ite.hasNext()) { diff --git a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/services/WebhooksService.java b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/services/WebhooksService.java index 32c91165..d88acc68 100755 --- a/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/services/WebhooksService.java +++ b/ipp-v3-java-devkit/src/main/java/com/intuit/ipp/services/WebhooksService.java @@ -48,6 +48,9 @@ public class WebhooksService { * define algorithm */ private static final String ALGORITHM = "HmacSHA256"; + + /** Shared ObjectMapper instance (thread-safe, reuse for performance) */ + private static final ObjectMapper mapper = new ObjectMapper(); public boolean verifyPayload(String intuitSignature, String payload) { try { @@ -74,7 +77,6 @@ public WebhooksEvent getWebhooksEvent(String payload) { return null; } try { - ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(payload, WebhooksEvent.class); } catch (JsonParseException e) { LOG.error("Error while parsing payload", e);