javaee / jaxb-v2

Other
211 stars 100 forks source link

Problem with two jaxb:dom elements #798

Open glassfishrobot opened 13 years ago

glassfishrobot commented 13 years ago

Two consecutive elements with jaxb:dom annotations seems to get confused during unmarshalling. See attached schema.

For the following XML snippet:

<c:valueAssignment xsi:type="c:ValueAssignmentType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://xml.netbeans.org/schema/common">

xx c:foo/c:bar The unmarshalling produces obviously wrong output (the source code attached): Using JAXB Version: 2.2.3 source: [c:target: null] target: null Adding a separator element between and does not help. Also making mandatory does not help. So we are efficiently out of reasonable workarounds here. #### Environment Linux, Sun JDK 1.6.0_22, JAXB 2.2.3 in the endorsed directory for runtime (Netbeans 6.9.1) #### Affected Versions [2.2.3]
glassfishrobot commented 13 years ago

Reported by semancik

glassfishrobot commented 13 years ago

laune said: The XML schema is compiled into a class where two elements are annotated with @XmlAnyElement, which violates the JAXB Specification (section 8.9.6.2). xjc should refuse to compile this schema, with an appropriate diagnostic.

The proper way of using xsd:any in combination with is to have a single element within a (complex) type, e.g.

This collects all XML elements not associated with regular properties of ValueAssignmentType into @XmlAnyElement protected List any; providing the client code with all information required to process the unmapped XML elements. Cf. JAXB specification section 7.12.3.
glassfishrobot commented 13 years ago

@pavelbucek said: I concur with Wolfgang analysis (thanks!); this is xjc issue, not runtime.

Proposed way to implement what you want with jaxb:dom is also correct approach which you should take.

I looked into the source and looks like nice solution would require some changes in codemodel, concretely we need to allow extract annotation class from JAnnotationUse to make check for two or mode XmlAnyElement annotated field/method.

glassfishrobot commented 13 years ago

snajper said: Downgrading priority based on evaluation

glassfishrobot commented 13 years ago

File: common.xsd Attached By: semancik

glassfishrobot commented 13 years ago

File: jaxbtest.tar.gz Attached By: semancik

glassfishrobot commented 13 years ago

Was assigned to snajper

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAXB-798