[esb-issues] [JBoss JIRA] Commented: (JBESB-815) JAXB-Intros @XmlAttribute annotation handling issue
Tom Fennelly (JIRA)
jira-events at lists.jboss.org
Tue Aug 21 06:44:19 EDT 2007
[ http://jira.jboss.com/jira/browse/JBESB-815?page=comments#action_12373092 ]
Tom Fennelly commented on JBESB-815:
------------------------------------
Looks as though we have a patch for this issue, plus the addition of proxies for one or 2 more annotations. The donatoinn was made from Chris McClelland. Thanks Chris :-)
"Hi Tom,
I found a bug in JAXBIntroductions, in the support for annotating fields (as opposed to methods). It
fails because the proxies for XmlAttribute and XmlElement do not implement the annotationType()
method. I have made a patch containing the fixes, and I added support for XmlAccessorType while I
was at it.
Here's the patch:
http://www.swaton.ukfsn.org/patch.tar.bz2
With the patch you can do:
<Class name="blah.CustomerOrder">
<XmlAccessorType value="FIELD"/>
<Field name="header">
<XmlElement namespace="http://..."/>
</Field>
<Field name="items">
<XmlElement namespace="http://..."/>
</Field>
</Class>
Naturally, you can also bind to attributes, using XmlAttribute.
Also, I don't know about you but I hate using log4j directly. I prefer to use commons-logging as a
logging abstraction layer. The necessary changes to JAXBIntroductions to achieve this are minimal.
What do you think?
I have some more work in the pipeline, like support for XmlRootElement.
- Chris"
> 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: Transports, Web Services
> Affects Versions: 4.2 Milestone Release 3
> Environment: Windows XP v2002 sp2, JAVA 1.5_02
> Reporter: Sylvia Isler
> Assigned To: Tom Fennelly
>
> 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: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the esb-issues
mailing list