Azure-sdk-for-java: Expose ability to customize JSON serialization

Created on 8 Jun 2019  路  3Comments  路  Source: Azure/azure-sdk-for-java

Removed public ObjectMapper references which let users customize JSON serialization.

This was due to Azure/azure-cosmosdb-java#153 need a better option.

Client Cosmos Investigate v4-item feature-request

All 3 comments

After reading the following blog post: https://devblogs.microsoft.com/cosmosdb/difference-between-null-and-undefined/ I was wondering how to achieve this with the Java SDK.
The default ObjectMapper is configured to always serialize null fields.

I was stumbling across this when adding a ttl field to my entity class. I want to set a custom TTL when updating a particular Cosmos DB item, the majority of items will never need a custom TTL and can simply use the container TTL. Therefore, the field would be null.

But if I set the ttl field to null I get the following error:

The input ttl 'null' is invalid. Ensure to provide a nonzero positive integer less than or equal to '2147483647', or '-1' which means never expire.

The documentation here states that setting ttl to null works, although not quite sure if null has the same meaning there.

@kushagraThapar I'd like to see some solution here, as this really limits some advanced use cases of the SDK. So maybe you can move it out of the "parking lot" again and assign it a higher prio?

For example, you cannot use Kotlin classes out-of-the-box as https://github.com/FasterXML/jackson-module-kotlin is not registered in the static ObjectMapper hidden in the SDK. This forces you to annotate Kotlin classes manually as a very ugly workaround to get deserialization of immutable data classes working:

data class Email @JsonCreator constructor(
    @param:JsonProperty("email") val email: String // note the redundant specification of "email"
)

Or do some hack like calling Utils.getSimpleObjectMapper().registerModule(new KotlinModule()) on that static ObjectMapper instance at an early point of the application lifecycle.

For @dkroehan a workaround would be to use @get:JsonInclude(JsonInclude.Include.NON_NULL) (Kotlin) on the ttl class field.

@xinlian12 - thoughts on this issue ?

Was this page helpful?
0 / 5 - 0 ratings