Skip to content

@JacksonXmlElementWrapper as a @JsonCreator parameter not working #149

@dmikurube

Description

@dmikurube

Do you have a plan to make @JacksonXmlElementWrapper specifiable as a parameter?

I'm wondering to use Jackson-dataformat-XML to deserialize to a immutable class instance, but @JacksonXmlElementWrapper is not available as a @JsonCreator parameter. We do a similar approach for JSON by specifying @JsonProperty on @JsonCreator.

For example:

{
  "type": "TYPE",
  "labels": [ "foo", "bar" ]
}

<body>
  <type>TYPE</type>
  <labels><label>foo</label><label>bar</label></labels>
</body>

@JacksonXmlRootElement(localName="body")
public class Body {
    @JsonCreator
    public Body(@JsonProperty("type")
                @JacksonXmlProperty("type")
                String type,
                @JsonProperty("labels")
                @JacksonXmlElementWrapper(localName="labels")
                @JacksonXmlProperty(localName="label")
                Collection<String> labels) {
        // ...
    }

    @JsonProperty("type")
    @JacksonXmlProperty("type")
    public String getType() { return this.type; }

    @JsonProperty("labels")
    @JacksonXmlElementWrapper(localName="labels")
    @JacksonXmlProperty("label")
    public ImmutableList<String> getLabels() { return this.labels; }

    private final String type;
    private final ImmutableList<String> labels;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issuepr-neededFeature request for which PR likely needed (no active development but idea is workable)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions