Skip to content

@JacksonXmlElementWrapper ignored on Stream #329

Open
@ndionisi

Description

@ndionisi

jackson-dataformat-xml version: 2.9.8

When using an XMLMapper with Jdk8Module to serialize Streams, the serializer seems to ignore annotation @JacksonXmlElementWrapper placed on a Stream.
For example, if I try to serialize this DTO as XML:

public class StreamBasedDto {
        private Stream<String> data;

        @JacksonXmlElementWrapper(localName = "elements")
        @JacksonXmlProperty(localName = "element")
        public Stream<String> getData() {
            return data;
        }

        public void setData(Stream<String> data) {
            this.data = data;
        }
    }

I get the following result:

<StreamBasedDto>
    <element>foo</element>
    <element>bar</element>
</StreamBasedDto>

whereas I was expecting the following:

<StreamBasedDto>
    <elements>
        <element>foo</element>
        <element>bar</element>
    </elements>
</StreamBasedDto>

You can find a Java project reproducing the issue here: https://github.com/ndionisi/jackson-xml-element-wrapper-stream. The project tests that @JacksonXmlElementWrapper is properly taken into account when serializing List, but not when serializing Stream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.16For issues planned for 2.16

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions