You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched in the issues and found nothing similar.
I searched in the issues of databind and other modules used and found nothing similar.
I have confirmed that the problem only occurs when using Kotlin.
Describe the bug
I am encountering a problem where the field order is not preserved after serializing and deserializing objects in Jackson.
I need access to only one specific field (transactionId), while I want to pass the remaining fields as they are, preserving the order in which they appear. I expected the transactionId field order might change, but I did not expect the order of the other fields (a, b, c) to change, especially in the second and third tests (SecondObject and ThirdObject). The data inside the c array is preserved in the expected order, but the surrounding fields are re-ordered.
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.
First Test Result (Passes):
The first test for FirstObject passes as expected, with the field order being preserved.
Repository for Reproduction:
You can find a repository with the full reproduction of the issue at jackson-databind-sorting-issue.
Expected behavior
For SecondObject and ThirdObject, after serializing the object back to JSON, I expect the transactionId field to appear at the top, followed by the fields b, a, and c, in the exact order they were present when the JSON was deserialized into SecondObject and ThirdObject.
Quick question: version affected is listed as 2.17.2 -- but how about 2.18.0.
Or, assuming 2.18.0 affected, would it be possible to test with 2.18.1-SNAPSHOT (of both jackson-databind and jackson-module-kotlin -- from Sonatype OSS Snapshots or locally built from 2.18 branches).
The reason I suggest this is because there have now been multiple small but significant fixes in 2.18 branch wrt any-setters so there is non-trivial chance this might be of one of fixes from:
Search before asking
Describe the bug
I am encountering a problem where the field order is not preserved after serializing and deserializing objects in Jackson.
I need access to only one specific field (transactionId), while I want to pass the remaining fields as they are, preserving the order in which they appear. I expected the transactionId field order might change, but I did not expect the order of the other fields
(a, b, c)
to change, especially in the second and third tests (SecondObject and ThirdObject). The data inside thec
array is preserved in the expected order, but the surrounding fields are re-ordered.To Reproduce
Tested Objects:
Input JSON for tests:
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.
First Test Result (Passes):
The first test for FirstObject passes as expected, with the field order being preserved.
Failing Test Results:
Expected:
For SecondObject was:
For ThirdObject was:
Repository for Reproduction:
You can find a repository with the full reproduction of the issue at jackson-databind-sorting-issue.
Expected behavior
For SecondObject and ThirdObject, after serializing the object back to JSON, I expect the
transactionId
field to appear at the top, followed by the fieldsb
,a
, andc
, in the exact order they were present when the JSON was deserialized into SecondObject and ThirdObject.Versions
Kotlin: 2.0.0
Jackson-module-kotlin: 2.17.2
Jackson-databind: 2.17.2
Additional context
This issue is a duplicate of 4751. I'm trying to reproduce it with Java, but it seems like all the described cases are specific to Kotlin
The text was updated successfully, but these errors were encountered: