users@jaxb.java.net

Re: XJC frustration

From: Brian Pontarelli <brian_at_pontarelli.com>
Date: Tue, 27 Mar 2007 10:40:57 -0600

Kohsuke Kawaguchi wrote:
> Brian Pontarelli wrote:
>> Just wanted to put this out on the list because I spent a number of
>> hours trying to get XJC to play nice and finally gave up in favor of
>> hand coding because it just would not get with the program. I have this:
>>
>> <xs:complexType name="entry" mixed="true">
>> <xs:sequence>
>> <xs:element name="phrase" type="xs:string" minOccurs="1"
>> maxOccurs="1"/>
>> </xs:sequence>
>> </xs:complexType>
>
> I'm sorry to hear that XJC wasted your time.
It wasn't a waste of time. I think I was just over-reacting to a small
problem. That's what waking up at 5:00 am and coding straight for 12
hours and then repeating for a few days will do to you. Sorry for being
such a joker about it.

>
>
>> and no matter if I changed the type of the "phrase" element to a
>> complex type, or a simple type or just used the inline schema types
>> like this it would generate this code:
>>
>> @XmlElementRef(name = "phrase", namespace =
>> "http://www.inversoft.com/schemas/profanity-1.0/database", type =
>> JAXBElement.class)
>> @XmlMixed
>> protected List<Serializable> content;
>
> The reason why it did this is because the complex type has a mixed
> content, so XJC thought you needed to distinguish ordinary string and
> the <phase> element. So it figured you need a heterogeneous list of
> String and Phase element, and the best common base type it was able to
> figure out was Serializable (whether XJC should ever use Serializable
> has been a subject of debate --- it doesn't seem to provide any type
> safety over Object.)
You are totally correct. I figured this out Sunday evening. I was only
looking at the problem in front of me and not all solutions. Again,
definitely due to too many hours and not enough sleep. But I did want a
text block and just didn't want to force myself to iterate over a list
and pick stuff out of it. So, I think the best solution is mixed = false
and a new element called text or something. This would solve the issue
nicely.

Thanks for the response and sorry again for being lame.

-bp