Hi,
I have posted email message to the CXF users mail list. Thanks to Sergey
Beryozkin, whose message is below, it looks like that the problem belongs to
JAXB, not to CXF. Could you guys please look at it and advise?
Thanks in advance
--- Karen
Below are Sergey's response and my original email (second)
>
> Hi
>
> I'm presuming you have a method like this one :
>
> I've experimented a bit and I've managed to have a test producing the
> expected data, but only when using an explicit JAXBElement, this one
>
> @Test
> public void testWriteDerivedTypeJaxbElement() throws Exception {
> JAXBElementProvider provider = new JAXBElementProvider();
> Method m = CollectionsResource.class.getMethod("getBaseJaxb", new
> Class[0]);
> DerivedType derived = new DerivedType();
> JAXBElement<BaseType> jaxb = new
> JAXBElement<BaseType>(_Base_QNAME,
> BaseType.class, null, derived);
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> provider.writeTo(jaxb, m.getReturnType(),
> m.getGenericReturnType(),
> new Annotation[0], MediaType.TEXT_XML_TYPE, new
> MetadataMap<String, Object>(), bos);
> String s = bos.toString();
> System.out.println(s);
>
> }
>
> produces
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:base
> xmlns:ns2="http://www.cisco.com/dms/xml/ns/dsmCommonService"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="ns2:DerivedType"/>
>
> public class RootResource {
> @GET
> public BaseType getType() { return new DerivedType(); }
> }
>
> I'm not sure why JAXB chooses to serialize it as
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:derivedType
> xmlns:ns2="http://www.cisco.com/dms/xml/ns/dsmCommonService"/>
>
> in this case, given that ObjectFactory has a method returning
> JAXBElement<BaseType>. I tried to force an ObjectFactory method returning
> JAXBElement<BaseType> be used, I removed @XmlRootElement on BaseType but
> it
> didn't make any difference. Removing @XmlRootElement on DerivedType causes
> a
> JAXB failure - though ObjectFactory has a method returning
> JAXBElement<DerivedType>.
>
> Can you please post a question to the JAXB users list ? I'd be interested
> to
> see what they reply. Unless our resident experts (Dan, Benson) can help ?
>
> thanks, Sergey
>
>
> Hi,
>
> I'm having a strange problem with CXF RESTful service marsahlling base and
> derived xsd types.
>
> XSD:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> xmlns="http://www.cisco.com/dms/xml/ns/dsmCommonService"
> targetNamespace="http://www.cisco.com/dms/xml/ns/dsmCommonService"
> elementFormDefault="unqualified" jaxb:version="2.0">
>
> <xs:complexType name="BaseType">
> <xs:sequence>
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="DerivedType">
> <xs:complexContent>
> <xs:extension base="BaseType">
> <xs:sequence>
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> <xs:complexType name="ListType">
> <xs:sequence>
> <xs:element name="item" type="BaseType" minOccurs="0"
> maxOccurs="unbounded" />
> </xs:sequence>
> </xs:complexType>
>
> <xs:element name="base" type="BaseType" />
> <xs:element name="derived" type="DerivedType" />
> <xs:element name="list" type="ListType" />
>
> </xs:schema>
>
> xjc has been used to jenerate java code from xsd. After that:
>
> 1) @XmlSeeAlso pointing to DerivedType class and @XmlRootElement
> annotations have been added to BaseType java class code
> 2) @XmlRootElement has been added to DerivedType java class code
> 3) @XmlRootElement has been added to ListType java class code
>
> When my CXF rest service returns list of the Derived objects it produces
> xml
> correctly:
>
> <list>
> <base xsi:type="DerivedType">...</base>
> ...
> <base xsi:type="DerivedType">...</base>
> </list>
>
> But when I'm requesting 1 instance of the Derived object XML is wrong (as
> I
> understand)
>
> <derived>...</derived>
>
> Since I did not specify substitution group in my opinion xml should be
> like
> in list:
>
> <base xsi:type="DerivedType">...</base>
>
> Could you please clarify the issue for me and may be help me to solve this
> problem.
>
>
--
View this message in context: http://www.nabble.com/Strange-JAXB-problem-with-derived-XSD-schema-elements-tp24570605p24570844.html
Sent from the java.net - jaxb dev mailing list archive at Nabble.com.