-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
After upgrading Jackson from version 2.17.2 to 2.18.0, the serialization process for SecondObject and ThirdObject has completely broken. The fields are either missing or partially serialized, making the resulting JSON incomplete.
I expected that only the field order might change, but now fields that were present in the input JSON are missing from the serialized output entirely.
Version Information
2.18.0
Reproduction
Tested objects:
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE
)
class FirstObject {
@field:JsonAnySetter
@field:JsonAnyGetter
val data: Map<String, Any?> = LinkedHashMap()
val transactionId: String
get() = data["transactionId"] as String
}
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE
)
class SecondObject(
val transactionId: String
) {
@field:JsonAnySetter
@field:JsonAnyGetter
val data: Map<String, Any?> = LinkedHashMap()
}
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE
)
class ThirdObject(
val transactionId: String,
@field:JsonAnySetter
@field:JsonAnyGetter
val data: Map<String, Any?> = LinkedHashMap()
)
Input JSON for tests:
{
"b": 2,
"a": 1,
"transactionId": "test",
"c": [
{
"id": "3",
"value": "c"
},
{
"id": "1",
"value": "a"
},
{
"id": "2",
"value": "b"
}
]
}
Test Case:
Here’s a test case to reproduce the issue. The following Kotlin test serializes and deserializes three different classes (FirstObject, SecondObject, and ThirdObject), comparing the serialized JSON with the original input JSON.
JacksonSortingTest.kt branch 2.18.0.
For FirstObject, however, the test passed successfully. All fields were present in the serialized JSON, and they appeared in the expected order, as in the original input JSON.
Failing Test Results:
Expected:
{
"b": 2,
"a": 1,
"transactionId": "test",
"c": [
{
"id": "3",
"value": "c"
},
{
"id": "1",
"value": "a"
},
{
"id": "2",
"value": "b"
}
]
}
For SecondObject was:
{
"transactionId": "test",
"c": [
{
"id": "3",
"value": "c"
},
{
"id": "1",
"value": "a"
},
{
"id": "2",
"value": "b"
}
]
}
For ThirdObject was:
{
"transactionId": "test"
}
Repository for Reproduction:
You can find a repository with the full reproduction of the issue at jackson-databind-sorting-issue - branch 2.18.0.
Expected behavior
After updating from Jackson 2.17.2 to 2.18.0, the serialization for SecondObject and ThirdObject should work as it did in the previous version (except for field ordering after deserialization and serialization). The expected JSON output after deserialization and serialization should contain all fields, with their values exactly as they are in the original input, regardless of field order.
Additional context
No response