microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

Customized ZonedDateTime format in ObjectMapper gets overridden #380

Closed kxmas closed 4 years ago

kxmas commented 5 years ago

My own custom ZonedDateTime format is overridden by the com.microsoft.azure.spring.data.cosmosdb.core.convert.MappingDocumentDbConverter.readInternal method

Here is the culprit: https://github.com/microsoft/spring-data-cosmosdb/pull/264

objectMapper.registerModule(provideAdvancedSerializersModule());

kushagraThapar commented 5 years ago

Hello @kxmas , yes this is an issue, and we are fixing it soon. I am planning to register the modules in MappingDocumentDbConverter constructor, and not on the readInternal method, would that be okay ?

Also, I noticed that MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS(true) is enabled by default, so registering shouldn't have overloaded your ZonedDataTimeFormatter because it takes the first registered module and skips any more registering if the module has the same name.

kxmas commented 5 years ago

Hi @kushagraThapar,

As I understand it, modules are collections of formatters, and not the formatters themselves, so to me it's not clear what the behavior will be.

My problem with the code is that it was registering the formatter every time it deserialized something. Moving that registration out of readInternal is the right thing to do, which is why I also did that in the PR I opened (and is still open).

Kevin

kushagraThapar commented 4 years ago

@kxmas , merged the PR, closing this issue.