You can use a bindingsfile like the following to avoid getting jaxbelements:
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
        <jaxb:globalBindings generateElementProperty="false">
</...

There is one snag with it though - and that is:
http://java.net/jira/browse/JAXB-864



2011/10/24 Daniel Kulp <[email protected]>:
> On Monday, October 24, 2011 7:24:30 PM KARR, DAVID wrote:
>> > -----Original Message-----
>> > From: James Carr [mailto:[email protected]]
>> > Sent: Monday, October 24, 2011 12:00 PM
>> > To: [email protected]
>> > Subject: JAXBElement<?> in generated java classes
>> >
>> > Hi,
>> >
>> > We've been using wsdl2java to generate our java classes for a
>> > wsdl-first webservice called by salesforce and one annoyance is that
>> > all the class members are of type JAXBElement<String>. Is there
>> > someway to override this behavior and make them the generic type of
>> > the JAXBElement? I'd like to use these as simple properties rather
>> > than calling "getCity().getValue()" all the time. :)
>>
>> Typically, when I've seen JAXBElement<whatever> types produced, it's due to
>> a suboptimal schema definition.  Specifically, if you're using anonymous
>> types.
>
> Well, the other place they are generated is if you have elements with BOTH
> minOccurs=0 and nillable=true.   Again, kind of sub-optimal schema.   The main
> reason is that JAXB needs to distinguish which of those you need.   In
> minOccurs=0 case, the JAXBElement itself would be null.   In the nillable
> case, the JAXBElement would not be null, but it's value would be.
>
> If the schema is EITHER minOccurs=0 OR nillable=true, it can just generate the
> type and if null, selects the right thing to do.
>
> You could likely write an XJC plugin that would convert the JAXBElements to
> their pure type.   I thought jaxb-commons had one, but it apparently doesn't.
>
>
> --
> Daniel Kulp
> [email protected]
> http://dankulp.com/blog
> Talend - http://www.talend.com
>



-- 
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen

Reply via email to