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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
minxylynxcommented, Oct 10, 2022

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

0reactions
michielboekhoffcommented, Oct 10, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom PropertyNamingStrategy not working in jackson
But it seems like that mu NamingStratergy is not working and it is not able to convert the snake_case to camel case and...
Read more >
ObjectMapper.setPropertyNamingStrategy - Java - Tabnine
public void setNamingStrategy(PropertyNamingStrategy naming) { setPropertyNamingStrategy(naming);
Read more >
Deserialize Snake Case to Camel Case With Jackson
As Java usually uses camel case field naming by convention, this makes it harder to deserialize snake case JSON. We look at some...
Read more >
Ditching Gson's Field Naming Strategy | by Sebastiano Gottardo
The lack of annotations ... Gson normally uses the member name as the JSON key, but by using @SerializedName you can provide a...
Read more >
How to Use PropertyNamingStrategy in Jackson
Jackson follows standard bean convention in mapping json fields to java object fields , but if you have a json which does not...
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