Hi Sergey,

Thanks a lot for so fast response and your investigation. I have posted my
initial email and your response to jaxb nabble.




Sergey Beryozkin wrote:
> 
> Hi
> 
> 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"/>
> 
> I'm presuming you have a method like this one :
> 
> 
> 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
> 

-- 
View this message in context: 
http://www.nabble.com/Possible-problem-with-JAXB-marshalling-tp24549727p24570653.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to