What the JAXB spec says: XmlAnyAttribute collision with explicit mapped attribute

Scenario

Consider the following class (import omitted):

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class Test {

    @XmlAttribute
    public int id;

    @XmlAnyAttribute
    public Map<QName,String> any;

}

What is the behavior when I do the following:

Test t = new Test();
t.id = 5;
t.any = new HashMap<QName,String>();
t.any.put(new QName("id"), "10");
JAXBContext jc = JAXBContext.newInstance(Test.class);
Marshaller m = jc.createMarshaller();
m.setEventHandler(myEventHandler);
m.marshal(t, System.out);

The obvious problem:

An XML element must be generated for the instance Test. But the obvious problem: with what attributes? <test id="5"/>? Or <test id="10"/>? Or invalid XML <test id="5" id="10"/>?

Answer, please:

  • Will marshalling succeed (or will there be an exception?)

  • It will be called handleEvent(ValidationEvent)of myEventHandler? If so, with what?

  • What can you expect on System.out, i.e., XML output? (If 1. the answer is positive)

  • Will (standardly appropriate) JAXB marshaller generate well-formed XML? (The circuit is not involved)

  • , <test id="5" id="10"/> , JAXB?

, :

, . Javadoc JAXB. , , .

+4
1

. EclipseLink JAXB (MOXy) JAXB (JSR-222).

JAXB

JAXB (JSR-222) : https://jcp.org/en/jsr/detail?id=222

  • ( ?)

    JAXB 2.2 , . (. B.3.6.2).

  • handleEvent (ValidationEvent) myEventHandler? , ?

    JAXB 2.2 .

  • System.out, XML? ( 1. )

    - undefined. , , MOXy JAXB .

  • ( ) JAXB marshaller XML? ( )

    , .

  • , , JAXB?

    marshalling undefined, ( MOXy) JAXB .

, , .

, Jira .

+3

Source: https://habr.com/ru/post/1523437/


All Articles