[FEATURE REQ] Cosmos v4 - Provide ability to specify ObjectMapper instance
See original GitHub issueIs your feature request related to a problem? Please describe.
When using the Cosmos SDK from Kotlin, we need to register the Kotlin module with the ObjectMapper
that will deserialize the Cosmos document or else it does not work correctly. We also choose specific serialization/deserialization options to meet our needs.
More specifically, in the context of Spring Boot, the serialization across the application is controlled by the instance of ObjectMapper
that is configured via Spring’s auto-configuration.
As it currently stands with v4 of the SDK, I don’t see any obvious hooks into (de)serialization. As a result, I have to first deserialize into an intermediate representation (I’m using CosmosItemProperties
since that is effectively what v3 did, but I could use Map<String, Any?>
), and then I convert that value to the Kotlin data class using my fully customized ObjectMapper
instance. On the outbound code path, I do something similar.
This double (de)serialization results in highly unnecessary CPU usage in our applications. For an SDK revision that claims to be focusing on optimization [https://devblogs.microsoft.com/cosmosdb/java-sdk-v4-ga/], not providing abstract code paths for one of the most CPU intensive parts of the SDK is very regrettable.
Describe the solution you’d like
We would like hooks to either provide a custom configured instance of ObjectMapper
, or to configure the ObjectMapper
that is used by the SDK. Currently, the hard coded (de)serialization uses Utils.getSimpleObjectMapper()
to use a lightly customized ObjectMapper
. I’d like to be able to provide an ObjectMapper
to the SDK during initialization that will be used to (de)serialize documents when upserting or querying.
Describe alternatives you’ve considered
You could go further, and provide fully customizable entry points for (de)serialization so that (de)serialization isn’t tied directly to Jackson at all. Such an API might be functional and provide a T
for serialization and a byte array for deserialization.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Description Added
- Expected solution specified
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Unfortunately, this workaround doesn’t work in my case. In the case in your POJO you have a Java 8 Time Field as below:
@JsonProperty("datetime") private ZonedDateTime datetime;
The conversion to ObjectNode node fails all the same. @kushagraThapar maybe could be a good solution to be able to set a custom object mapper.
P.S. Test has been done with version 4.24.0
Above mentioned workaround is the only way right now, closing this issue now.