jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Possible Bug: `.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)` doesnt respect the naming strategy

Open minxylynx opened this issue 3 years ago • 3 comments

Describe the bug

I am declaring a global ObjectMapper as such:

val OBJECT_MAPPER = ObjectMapper()
    .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
    .registerKotlinModule()
    .registerModule(JavaTimeModule())
    .registerModule(ProtobufModule())
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    .setSerializationInclusion(JsonInclude.Include.NON_NULL)
    .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

This worked prior to upgrade to 2.12.5 using

val OBJECT_MAPPER = ObjectMapper()
    .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)  <---- notice the deprecated usage
    ...

However, now when I use something like fun GeneratedMessageV3.toProcedureObject() = OBJECT_MAPPER.writeValueAsString(this), the naming strategy is no longer respected. It is using camelCase instead.

I cant figure out why; Ive tracked it to where it shows the naming strategy (which shows correctly), but thats as far I was able to get.

Version information

2.12.5, upgrading from 2.11.4

To Reproduce Using the above setup, it doesnt serialize correctly.

Additional context

Kotlin 1.5.31

minxylynx avatar Feb 14 '22 01:02 minxylynx

Current work around is to use the deprecated class, as that still works for 2.12.5

minxylynx avatar Feb 14 '22 01:02 minxylynx

Looking at all the modules registered it is difficult to know what is to blame, but my guess would be ProtobufModule or Kotlin module. I doubt this is reproducible with just jackson-databind, but without knowing what is involved it is not possible to transfer the issue either.

@minxylynx Would it be possible to try to isolate module(s) that are involved? If it is reproducible with databind, I can have a look. Otherwise issue needs to be transferred to another repo as databind cannot have a dependency to any module not defined within its codebase.

cowtowncoder avatar Feb 14 '22 21:02 cowtowncoder

Marking with "need-test-case" just to indicate that while there is a test, it does not isolate the problem well enough yet to be actionable, unfortunately.

cowtowncoder avatar Mar 29 '22 16:03 cowtowncoder

@minxylynx -

I'm pretty sure this is an issue with the ProtobufModule, which is something we ran into as well. Specifically, support for the new PropertyNamingStrategies has been implemented in master (see also here) however, it has not been released to mvncentral yet.

Therefore, I think this issue can actually be closed & an issue should be opened against the repo for jackson-datatype-protobuf.

michielboekhoff avatar Oct 10 '22 07:10 michielboekhoff

@michielboekhoff I agree. I opened up an issue to release out jackson-datatype-protobuf with the latest of whats in there.

minxylynx avatar Oct 10 '22 15:10 minxylynx