PropertyNamingStrategy doesn't work during deserialization
See original GitHub issuesimple 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:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!@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.