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

Jackson 2.12.3 and later fails to collapse XML list using @JsonAlias #721

Open
henrik242 opened this issue Nov 1, 2023 · 2 comments
Open
Labels

Comments

@henrik242
Copy link

henrik242 commented Nov 1, 2023

As described in this blog post it has been possible to deserialize this:

    <LedgerTransactionDetails>
      <LedgerActivityDetailObject>
        <Amount>1056.38</Amount>
        <TransactionType>Simple</TransactionType>
      </LedgerActivityDetailObject>
    </LedgerTransactionDetails>

... into a collaped list like this:

data class LedgerActivityDetail(
        @set:JsonProperty("TransactionType")
        var loanType: String? = null,

        @set:JsonProperty("Amount")
        var amount: String? = null
)

@JsonRootName("LedgerActivityObject")
data class LedgerActivity(

        @set:JsonProperty("LedgerTransactionDate")
        var LedgerTransactionDate: String? = null,

        @set:JsonProperty("Amount")
        var amount: String? = null,

        // HERE IS WHERE THE MAGIC HAPPENS!!!
        @set:JsonAlias("LedgerTransactionDetails", "LedgerActivityDetailObject")
        var LedgerActivityDetails: List<LedgerActivityDetail> = ArrayList()
)

This worked until jackson 2.12.2. In 2.12.3 and onwards (including 2.16.0-rc1) the inner values of LedgerActivityDetail are null

Here's a test project: https://github.com/henrik242/jackson-xml-problem/blob/list-wrappers/src/test/kotlin/jackson/xml/ListWrappersTest.kt

@henrik242
Copy link
Author

@cowtowncoder Any ideas if this should be possible somehow in jackson 2.12.3+? I'm not familiar with how this is supposed to work in newer versions.

@cowtowncoder
Copy link
Member

From little reading this does not seem like a reliable way to work around problems, i.e. might appear to work by accident more than intentionally.

But as usual, one important part in de-tangling problems is trying to figure out what part is due to Kotlin (annotations being associated with accessors as needed), and which XML format module (and possibly even jackson-databind occasionally).
So pure-Java reproduction would be useful to show something is not Kotlin-specific (if so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants