question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQ] Cosmos v4 - Provide ability to specify ObjectMapper instance

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
apescionecommented, May 19, 2022

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

0reactions
kushagraThaparcommented, Sep 8, 2020

Above mentioned workaround is the only way right now, closing this issue now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build a Java web app using Azure Cosmos DB and the API for ...
Tutorial: This Java web application tutorial shows you how to use the Azure Cosmos DB and the API for NoSQL to store and...
Read more >
How do I obtain the Jackson ObjectMapper in use by Spring ...
I have reason to want to @Autowire that instance into one of my controllers: The controller does some minor JSON parsing of its...
Read more >
Spring Cloud Azure - Reference Documentation
Spring Cloud Azure 4.0 provides five common categories of configuration properties, which could be specified to each Azure service.
Read more >
Learn Live - Configure the Azure Cosmos DB SQL API SDK
Full series information: https://aka.ms/learnlive-azure-cosmosdb-certMore info here: https://aka.ms/learnlive-azure-cosmosdb-cert-Ep5Follow ...
Read more >
Spring Data Commons - Reference Documentation
method that's used to set the identifier, e.g. when an instance is ... provide sophisticated CRUD functionality for the entity class that is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found