diff --git a/commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/Serialization.java b/commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/Serialization.java index fccff93a385..413b529bc52 100644 --- a/commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/Serialization.java +++ b/commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/Serialization.java @@ -11,7 +11,7 @@ * The default configured {@link com.fasterxml.jackson.databind.ObjectMapper} uses some modules to correctly work with our API. * The details can be found in {@link io.vrap.rmf.base.client.utils.json.JsonUtils#createObjectMapper(ModuleOptions)}
* - *To allow customization of the ObjectMapper the SDK uses {@link java.util.ServiceLoader} for * {@link io.vrap.rmf.base.client.utils.json.ModuleSupplier}. Adding a file @@ -23,13 +23,20 @@ * {@include.file commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/json/ApiModule.java} *
* - *When using Date, Time and DateTime types for product attributes or custom fields the SDK deserializes them as {@link java.time.LocalDate}, * {@link java.time.LocalTime} and {@link java.time.ZonedDateTime}. As sometimes it may needed to serialize them as {@link String} the ObjectMapper * can be configured with {@link ModuleOptions}. The {@link com.commercetools.api.json.ApiModule} also is loading the configuration options * using {@link System#getProperty(String)} e.g.: {@link com.commercetools.api.json.ApiModuleOptions#DESERIALIZE_DATE_ATTRIBUTE_AS_STRING commercetools.deserializeDateAttributeAsString}
* {@include.example example.SerializationTest#dateAsString()} + * + *In case the automatic deserialization of attributes is not needed. You can set the {@link com.commercetools.api.json.ApiModuleOptions#DESERIALIZE_ATTRIBUTE_AS_JSON_NODE commercetools.deserializeAttributeAsJsonNode} an/or + * {@link com.commercetools.api.json.ApiModuleOptions#DESERIALIZE_CUSTOM_FIELD_AS_JSON_NODE commercetools.deserializeCustomFieldAsJsonNode}
+ * + * {@include.example example.SerializationTest#jsonNodes()} */ public class Serialization { } diff --git a/commercetools/internal-docs/src/test/java/example/SerializationTest.java b/commercetools/internal-docs/src/test/java/example/SerializationTest.java index f18bd42cca0..7272d6e2874 100644 --- a/commercetools/internal-docs/src/test/java/example/SerializationTest.java +++ b/commercetools/internal-docs/src/test/java/example/SerializationTest.java @@ -69,4 +69,15 @@ public void dateAsString() throws JsonProcessingException { .first() .isInstanceOf(ZonedDateTime.class); } + + @Test + public void jsonNodes() throws JsonProcessingException { + ApiModuleOptions options = ApiModuleOptions.of().withCustomFieldAsJsonNode(true).withAttributeAsJsonNode(true); + ObjectMapper mapper = JsonUtils.createObjectMapper(options); + + ProjectApiRoot apiRoot = ApiRootBuilder.of() + .withApiBaseUrl(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl()) + .withSerializer(ResponseSerializer.of(mapper)) + .build("test"); + } }