JAXB-Intros @XmlAttribute annotation handling issue
---------------------------------------------------
Key: JBESB-815
URL:
http://jira.jboss.com/jira/browse/JBESB-815
Project: JBoss ESB
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Web Services, Transports
Affects Versions: 4.2 Milestone Release 3
Environment: Windows XP v2002 sp2, JAVA 1.5_02
Reporter: Sylvia Isler
Assigned To: Tom Fennelly
Fix For: 4.2.1 IR1
Attachments: patch.tar.bz2
JAXB with JAXB-introductions fails to Marshall @XmlAttribute annotations in the following
example:
The following class contains a simple double for an attribute:
public class UnitPrice {
public double value;
UnitPrice(double value){
this.value=value;
}
UnitPrice()
{
}
public double getValue()
{
return this.value;
}
}
The following JAXB-intros config file was used
<?xml version = "1.0" encoding = "UTF-8"?>
<jaxb-intros
xmlns="http://www.jboss.org/xsd/jaxb/intros">
<Class name="junit.prices.UnitPrice">
<XmlType name = "UnitPrice"/>
<Field name="value">
<XmlAttribute name="value" required="true" />
</Field>
</Class>
</jaxb-intros>
along with the following schema file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="UnitPrice">
<xs:complexType>
<xs:attribute name="value" type=xs:double use="required"/>
<xs:attribute name="currency" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="USD"/>
<xs:enumeration value="Euro"/>
<xs:enumeration value="JPY"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
To unmarshall this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<UnitPrice value="40.0"
xsi:noNamespaceSchemaLocation="C:\UnitPrice.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
I then used the following code to test the unmarshalling of the above XML.
JaxbIntros config =
IntroductionsConfigParser.parseConfig(getClass().getResourceAsStream("UnitConfig.xml"));
ClassIntroConfig classIntroConfig = config.getClazz().get(0);
assertEquals(UnitPrice.class.getName(), classIntroConfig.getName());
IntroductionsAnnotationReader reader = new IntroductionsAnnotationReader(config);
Map<String, Object> jaxbConfig= new HashMap<String, Object>();
jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader);
JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] {UnitPrice.class},
jaxbConfig);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement jbe = null;
UnitPrice order =null;
StreamSource ss = new
StreamSource(getClass().getResourceAsStream("UsdUnitPrice1.xml"));
jbe = unmarshaller.unmarshal(ss, UnitPrice.class);
order =(UnitPrice)jbe.getValue();
try{
assertEquals("get double value error", 40.0, order.getValue());
} catch (Exception e) {
fail(e.getMessage());
}
a UnitPrice instance is instantiated. However, the above test code fails because the
value attribute of the unmarshalled UnitPrice instance is 0.0 instead of 40.0..
After some discussion on the forums, I decided to try using <Method> tag instead of
the <Field> in the config file above. When this yielded the same result,
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: