Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record property serialization order not preserved #4617

Closed
1 task done
GeorgiPetkov opened this issue Jul 9, 2024 · 7 comments
Closed
1 task done

Record property serialization order not preserved #4617

GeorgiPetkov opened this issue Jul 9, 2024 · 7 comments
Labels
2.18 Record Issue related to JDK17 java.lang.Record support

Comments

@GeorgiPetkov
Copy link

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Since 2.16.0 the order of record's properties is not preserved when @JsonProperty is present. This is not the case for version 2.15.X.

The impact:

  • breaking tons of tests related to signatures and similar use cases
  • overall worse order than the order defined in the record in terms of readability

Version Information

1.16.0+, works on 1.15.X

Reproduction

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class RecordPropertiesOrderTest {

    @Test
    void assertRecordPropertiesOrder() throws JsonProcessingException {
        assertEquals("{\"aa\":1,\"b\":2}", new ObjectMapper().writeValueAsString(new TestRecord(1, 2)));
    }

    private record TestRecord(@JsonProperty("aa") int a, int b) {
    }
}

Expected behavior

The properties in the JSON should be in the same order as defined in the record just like it behaves without the @JsonProperty annotation.

Additional context

No response

@GeorgiPetkov GeorgiPetkov added the to-evaluate Issue that has been received but not yet evaluated label Jul 9, 2024
@pjfanning
Copy link
Member

Could you try testing with 2.18.0-SNAPSHOT? This version contains more changes in the code handling property order.

@GeorgiPetkov
Copy link
Author

I don't know where to find this version. Is it released somewhere? You can test it yourself pretty easily given the provided test. It only depends on JUnit5 and Jackson.

@pjfanning
Copy link
Member

Snapshots are a commonly used way of testing pre-release changes. Jackson uses Sonatype for publishing jars.

Maybe reading reading the docs for your preferred build tool could e an option.

For Maven, this has some answers: https://stackoverflow.com/questions/16286055/how-to-get-snapshot-from-sonatype

@GeorgiPetkov
Copy link
Author

The test passes with the current 2.18.0-SNAPSHOT (jackson-databind-2.18.0-20240706.005235-157.jar).

Do you have any rough estimate regarding when we can expect release of 2.18.0?

@cowtowncoder
Copy link
Member

@GeorgiPetkov Most likely end of August -- need at least one Release Candidate and we are not yet ready for that. Plus I'll be on vacation last week of July, first of August.

@cowtowncoder cowtowncoder added 2.18 Record Issue related to JDK17 java.lang.Record support and removed to-evaluate Issue that has been received but not yet evaluated labels Jul 21, 2024
@cowtowncoder cowtowncoder changed the title Regression: not preserved record properties order Record property serialization order not preserved Jul 21, 2024
@cowtowncoder
Copy link
Member

Marked as resolved for 2.18.0.

@cowtowncoder
Copy link
Member

Note: 2.18.0-rc1 is out, release to be done this week (end of September).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Record Issue related to JDK17 java.lang.Record support
Projects
None yet
Development

No branches or pull requests

3 participants