users@jaxb.java.net

Re: Unmarshalling 'enum's

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 17 Aug 2012 10:31:40 +0200

The schema representation is something like
     <xs:simpleType name="Numbers">
       <xs:restriction base="xs:string"/>
         <xs:enumeration value="ONE"/>
      </ </
According to "XML Schema Part 2: Datatypes Second Edition", the
enumeration value must be identical to what's in the XML file; leading
and trailing white space violates equality.

So, the answer is: "yes".

-W

On 17/08/2012, Luc <useyour.mind_at_gmail.com> wrote:
> Hello!
>
> I'm using JAXB to marshal/unmarshal objects, and some of them are
> enumobjects and lists of that
> enum elements.
> But when unmarshalling a list of enum, there can't be any new line in the
> XML. In example:
>
> public enum Numbers {
>> ONE, TWO, THREE
>> }
>> private static class EnumList {
>> private ArrayList<Numbers> array = new ArrayList<Numbers>();
>> public EnumList() {}
>> public void setArray(ArrayList<Numbers> array) {
>> this.array = array;
>> }
>> public ArrayList<Numbers> getArray() {
>> return array;
>> }
>> }
>
>
> When unmarshalling an XML like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
>> <EnumList>
>> <list>ONE</list>
>> <list>TWO</list>
>> <list>THREE</list>
>> </EnumList>
>
>
> Works great, but if the third element has a new line before or after its
> name, JAXB returns a null:
>
> <?xml version="1.0" encoding="UTF-8"?>
>> <EnumList>
>> <list>ONE</list>
>> <list>TWO</list>
>> <list>
>
> THREE</list>
>>
> <!-- or
>> <list>THREE
>> </list>
>> -->
>
> </EnumList>
>
>
> Is this the expected behaviour?
> Thanks,
> --
> Lucas
>