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

Cannot use @JacksonXmlText on a constructor property #423

Closed
raphw opened this issue Sep 7, 2020 · 6 comments
Closed

Cannot use @JacksonXmlText on a constructor property #423

raphw opened this issue Sep 7, 2020 · 6 comments
Labels
has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue

Comments

@raphw
Copy link

raphw commented Sep 7, 2020

Unfortunately, it is not possible to use @JacksonXmlText on a constructor what can be required in combination with @JacksonXmlProperty(isAttribute = true) what prevents one from creating immutable entities.

For example, the following object cannot be expressed using a constructor so that the immutable property needs to be emulated.

class Sample {
    @JacksonXmlText
    private String text;
    @JacksonXmlProperty(localName = "attribute", isAttribute = true)
    private String attribute;

    protected Sample () { }

    public Sample (String text, String attribute) {
        this.text = text;
        this.attribute = attribute;
    }
}

It would be nicer being able to use @JacksonXmlText on a constructor parameter.

@cowtowncoder cowtowncoder added the to-evaluate Issue that has been received but not yet evaluated label Sep 8, 2020
@cowtowncoder
Copy link
Member

@raphw That does sound like a limitation. So, just do make sure I understand: adding equivalent annotations on constructor parameters (and not on fields) would not work?

@raphw
Copy link
Author

raphw commented Sep 9, 2020

No, if I add the annotation to the field and let the constructor parameter blank, an exception is thrown.

@cowtowncoder
Copy link
Member

@raphw ah. So while you can add @JsonProperty, that will mess handling ... I think there is a related issue, let me find it.

@cowtowncoder
Copy link
Member

I think #306 might be related or maybe same? Problem, under the hood, is that "XmlText" is internally denoted as logical name of "", which unfortunately conflicts with 'missing name' option....

@cowtowncoder
Copy link
Member

One quick note: #434 will allow use of @JacksonXmlText on (constructor) parameter. Likely it will not work, regardless, due to #306, but I will add a separate test for this case just to make sure.

@cowtowncoder cowtowncoder added 2.13 has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue and removed 2.12 to-evaluate Issue that has been received but not yet evaluated labels Nov 14, 2020
cowtowncoder added a commit that referenced this issue Nov 14, 2020
@cowtowncoder
Copy link
Member

Added a failing test along with #306; will close this as dup since I think it it the same underlying issue. Will close this issue, mark 306 as "most-wanted", hoping to address in 2.13 (or if lucky and doable in patch. 2.12.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants