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

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

Closed
aonnikov opened this issue May 7, 2018 · 1 comment
Closed
Milestone

Comments

@aonnikov
Copy link

aonnikov commented May 7, 2018

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.

@cowtowncoder
Copy link
Member

Thank you for reporting this. Seems like @XmlElements is not recognized as implicit inclusion marker, unlike @XmlElement.

@cowtowncoder cowtowncoder added this to the 2.9.6 milestone May 7, 2018
@cowtowncoder cowtowncoder changed the title @XmlElements does not work with @XmlAccessorType(XmlAccessType.NONE) @XmlElements does not work with @XmlAccessorType(XmlAccessType.NONE) May 7, 2018
stevenschlansker pushed a commit to stevenschlansker/jackson-modules-base that referenced this issue Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants