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.

PropertyNamingStrategy doesn't work during deserialization

See original GitHub issue

simple kotlin snippet to reproduce:

class JacksonTest {

    @Test
    fun testSnakeCaseDeserialization() {
        val json = """{"my_camel_case":10001}"""
        val objectMapper = jacksonObjectMapper().findAndRegisterModules()
        val obj = objectMapper.readValue<TestSnakeCase>(json)
        println(obj)
        assertEquals(10001, obj.myCamelCase)
    }

    @Test
    fun testSnakeCaseSerialization() {
        val objectMapper = jacksonObjectMapper().findAndRegisterModules()
        val obj = TestSnakeCase(10001)
        println(objectMapper.writeValueAsString(obj))
    }

    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
    data class TestSnakeCase(val myCamelCase: Int)
}

also happens in Java

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
unlimitedsolacommented, Nov 21, 2017

Oops, This is interesting, I didn’t notice it only happens on POJO that has exactly one property. add @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) and everything works fine. Thanks!

0reactions
cowtowncodercommented, Nov 22, 2017

@unlimitedsola Yes this is… sort of unfortunate thing, and commonly stumbled upon. So there are two interpretations here: with just 1 property, one could either consider mapping exact value (“delegating”), or JSON Object of just one property (“property-based”). Jackson tries to use heuristics if not explicitly specified but I don’t think there is anything that can ultimately tell it, short of allowing configuration for defaulting (mode used if not annotated) and allowing overrides.

mode property was added to allow explicit annotation: if you had added explicit name annotation with @JsonProperty this would also have happened. It is only ambiguous if name is derived from bytecode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JsonNaming not working with lombok builder - Stack Overflow
Above one is working fine and able to deserialize. But if I use lombok builder for deserialization, it's failing. Below is class with...
Read more >
PropertyNamingStrategy (jackson-databind 2.7.0 API)
Class that defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names"), in cases...
Read more >
Security update for jackson-databind, jackson-dataformats ...
Maximize the value of open source with SUSE solution, backed by SUSE Support. ... + '@JsonValue' with integer for enum does not deserialize...
Read more >
Jackson Property Custom Naming Strategy - DZone
To serialize or deserialize to/from POJO, Jackson uses a bean naming convention. To accomplish this, it uses annotations. Let's learn how in ...
Read more >
Class PropertyNamingStrategy - Red Hat Customer Portal
Since this is the native Java naming convention, naming strategy will not do any transformation between names in data (JSON) and POJOS. Since:...
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