Skip to content

@XmlElements does not work with @XmlAccessorType(XmlAccessType.NONE) #44

@aonnikov

Description

@aonnikov

I cannot get working @XmlElements and @XmlAccessorType(XmlAccessType.NONE) in Jackson 2.9.5. It ignores the field during serialization when I add XmlAccessorType annotation with NONE value.

@XmlElement works fine.

public class NoneAccessTest extends BaseJaxbTest {

    static class Foo {
        private String foo;

        public Foo() { }
        public Foo(String foo) { this.foo = foo; }

        public String getFoo() {
            return foo;
        }

        public void setFoo(String foo) {
            this.foo = foo;
        }
    }

    @XmlAccessorType(XmlAccessType.NONE)
    static class NoneAccessBean
    {
        @XmlElements({
                @XmlElement(type=Foo.class, name="foo")
        })
        public Object object;

        @XmlElement
        public Object other;

        public NoneAccessBean() { }
        public NoneAccessBean(Object o) { object = o; }
        public NoneAccessBean(Object o, Object b) {
            object = o;
            other = b;
        }
    }

    public void testNoneAccessWithXmlElements() throws Exception {
        NoneAccessBean input = new NoneAccessBean(new Foo("foo"));

        ObjectMapper mapper = getJaxbMapper();
        String str = mapper.writeValueAsString(input);
        assertEquals("{\"object\":{\"foo\":{\"foo\":\"foo\"}},\"other\":null}", str);
    }
}

Result is:

Expected :{"object":{"foo":{"foo":"foo"}},"other":null}
Actual   :{"other":null}

It used to work at least in 2.6 and seems to be a valid scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions