Skip to content

Commit

Permalink
add docs about json node attribute/custom field deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Nov 7, 2023
1 parent b63d823 commit 3b6de5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)}</p>
*
* <h3>Customization</h3>
* <h3 id="customization">Customization</h3>
*
* <p>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
Expand All @@ -23,13 +23,20 @@
* {@include.file commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/json/ApiModule.java}
* </p>
*
* <h3>Date and time attributes</h3>
* <h3 id="date-time-attributes">Date and time attributes</h3>
*
* <p>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}</p>
* {@include.example example.SerializationTest#dateAsString()}</p>
*
* <h3 id="JsonNodes">Use JsonNodes</h3>
*
* <p>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}</p>
*
* {@include.example example.SerializationTest#jsonNodes()}
*/
public class Serialization {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 3b6de5c

Please sign in to comment.