From 1febec1f7e4d0eb42cbfc17417eb457dec6f18f8 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 17 Oct 2024 11:40:43 +0200 Subject: [PATCH 1/6] Fix deserialization if subtype discriminator is missing --- .../com/commercetools/CartDiscountTest.java | 17 ++++++++++++++ .../rmf/base/client/utils/json/JsonUtils.java | 23 +++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/CartDiscountTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/CartDiscountTest.java index 6390100375e..db07c25257f 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/CartDiscountTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/CartDiscountTest.java @@ -4,7 +4,11 @@ import static org.assertj.core.api.Assertions.assertThat; import com.commercetools.api.models.cart_discount.*; +import com.commercetools.api.models.common.ReferenceTypeId; +import io.vrap.rmf.base.client.utils.json.JsonUtils; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; public class CartDiscountTest { @@ -94,4 +98,17 @@ public void giftLineItemValueToDraft() { }); } + + @Test + public void deserializeGiftLineItemWithoutTypeId() { + String json = "{\"value\": { \"type\": \"giftLineItem\", \"product\": { \"id\": \"foo\" } } }"; + CartDiscount cartDiscount = JsonUtils.fromJsonString(json, CartDiscount.class); + Assertions.assertThat(cartDiscount.getValue()) + .isInstanceOfSatisfying(CartDiscountValueGiftLineItem.class, cartDiscountValueGiftLineItem -> { + assertThat(cartDiscountValueGiftLineItem.getProduct().getId()).isEqualTo("foo"); + assertThat(cartDiscountValueGiftLineItem.getProduct().getTypeId()) + .isEqualTo(ReferenceTypeId.PRODUCT); + }); + Assertions.assertThat(cartDiscount.getValue()).isInstanceOf(CartDiscountValueGiftLineItem.class); + } } diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java index 0691fd9d9a9..62bbca335d6 100644 --- a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -52,17 +53,19 @@ public static ObjectMapper createObjectMapper(final ModuleOptions options) { final List moduleList = new ArrayList<>(); suppliers.iterator().forEachRemaining(moduleSupplier -> moduleList.add(moduleSupplier.getModule(options))); - final ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()) //provides serialization and deserialization for LocalDate and LocalTime (JSR310 Jackson module) - .registerModule(new ZonedDateTimeSerializationModule()) //custom serializer for LocalDate, LocalTime and ZonedDateTime - .registerModule(new ZonedDateTimeDeserializationModule()) //custom deserializer for ZonedDateTime - .registerModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate - .registerModules(loader) - .registerModules(moduleList) - .setSerializationInclusion(JsonInclude.Include.NON_NULL) //ignore null fields + return JsonMapper.builder() + .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - return objectMapper; + .configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false) + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .serializationInclusion(JsonInclude.Include.NON_NULL) + .addModule(new JavaTimeModule()) + .addModule(new ZonedDateTimeSerializationModule()) //custom serializer for LocalDate, LocalTime and ZonedDateTime + .addModule(new ZonedDateTimeDeserializationModule()) //custom deserializer for ZonedDateTime + .addModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate + .addModules(loader) + .addModules(moduleList) + .build(); } /** From d1fcde04ce3f19fd6c62ae524189b730fc9a73bd Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 17 Oct 2024 14:48:18 +0200 Subject: [PATCH 2/6] fix deserialization of subtypes without discriminator field --- gradle-scripts/extensions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-scripts/extensions.gradle b/gradle-scripts/extensions.gradle index 2af09bf4783..de9c4f45c3a 100644 --- a/gradle-scripts/extensions.gradle +++ b/gradle-scripts/extensions.gradle @@ -5,7 +5,7 @@ ext { convenience: 'com.commercetools.sdk.jvm.core:commercetools-convenience:2.16.0', version: { strictly '[1.62.0,)' - prefer '2.14.0' + prefer '2.16.0' } ] From c4fdbfd44be37df97909498da8cd11b0d554a860 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 17 Oct 2024 14:51:25 +0200 Subject: [PATCH 3/6] reorder objectmapper builder --- .../io/vrap/rmf/base/client/utils/json/JsonUtils.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java index 62bbca335d6..025cf6489e1 100644 --- a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java @@ -54,17 +54,16 @@ public static ObjectMapper createObjectMapper(final ModuleOptions options) { suppliers.iterator().forEachRemaining(moduleSupplier -> moduleList.add(moduleSupplier.getModule(options))); return JsonMapper.builder() - .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false) - .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .addModule(new JavaTimeModule()) + .addModule(new JavaTimeModule()) //provides serialization and deserialization for LocalDate and LocalTime (JSR310 Jackson module) .addModule(new ZonedDateTimeSerializationModule()) //custom serializer for LocalDate, LocalTime and ZonedDateTime .addModule(new ZonedDateTimeDeserializationModule()) //custom deserializer for ZonedDateTime .addModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate .addModules(loader) .addModules(moduleList) + .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .serializationInclusion(JsonInclude.Include.NON_NULL) .build(); } From f83ccd3db291db1c8f57e2eb571091db7bed9491 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 17 Oct 2024 14:52:23 +0200 Subject: [PATCH 4/6] reorder objectmapper builder --- .../java/io/vrap/rmf/base/client/utils/json/JsonUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java index 025cf6489e1..d46820f2e2e 100644 --- a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java @@ -60,10 +60,10 @@ public static ObjectMapper createObjectMapper(final ModuleOptions options) { .addModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate .addModules(loader) .addModules(moduleList) - .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) + .serializationInclusion(JsonInclude.Include.NON_NULL) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) - .serializationInclusion(JsonInclude.Include.NON_NULL) + .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) .build(); } From 4f1b9b2e1da4f10be57491fb8234b185a370c965 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 17 Oct 2024 14:53:25 +0200 Subject: [PATCH 5/6] add doc comment --- .../main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java index d46820f2e2e..585c17cb5b9 100644 --- a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/utils/json/JsonUtils.java @@ -60,7 +60,7 @@ public static ObjectMapper createObjectMapper(final ModuleOptions options) { .addModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate .addModules(loader) .addModules(moduleList) - .serializationInclusion(JsonInclude.Include.NON_NULL) + .serializationInclusion(JsonInclude.Include.NON_NULL) //ignore null fields .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) From 4f1f258fc4b15bc8c9e5ba2005d9f81a2093af57 Mon Sep 17 00:00:00 2001 From: "ct-sdks[bot]" <153784748+ct-sdks[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:59:57 +0000 Subject: [PATCH 6/6] TASK: Updating license information --- licenses/commercetools-sdk-compat-v1/index.json | 14 +++++++------- licenses/index.json | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/licenses/commercetools-sdk-compat-v1/index.json b/licenses/commercetools-sdk-compat-v1/index.json index a170c063b5b..bbae45a7130 100644 --- a/licenses/commercetools-sdk-compat-v1/index.json +++ b/licenses/commercetools-sdk-compat-v1/index.json @@ -2,7 +2,7 @@ "dependencies": [ { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -12,7 +12,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client-ahc-2_0", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -22,7 +22,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client-core", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -32,7 +32,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-models", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -42,7 +42,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-sdk-base", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -52,7 +52,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:sdk-http", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -62,7 +62,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:sdk-http-ahc-2_0", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", diff --git a/licenses/index.json b/licenses/index.json index 714d0883352..a5ca9be9d12 100644 --- a/licenses/index.json +++ b/licenses/index.json @@ -2,7 +2,7 @@ "dependencies": [ { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -12,7 +12,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client-ahc-2_0", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -22,7 +22,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-java-client-core", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -32,7 +32,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-models", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -42,7 +42,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:commercetools-sdk-base", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -52,7 +52,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:sdk-http", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0", @@ -62,7 +62,7 @@ }, { "moduleName": "com.commercetools.sdk.jvm.core:sdk-http-ahc-2_0", - "moduleVersion": "2.14.0", + "moduleVersion": "2.16.0", "moduleLicenses": [ { "moduleLicense": "Apache License, Version 2.0",