users@jaxb.java.net

Re: Flattened Binding / Unmarshalling

From: Christian Schleif <forum_at_schleif-online.de>
Date: Thu, 17 Jan 2008 16:24:03 +0100

Hi,

@XmlElementWrapper(name="a") results just the exception that b isn't a collection. Any other ideas?

regards
christian



Aleksei Valikov schrieb:
> Hi.
>
>> I have a problem. I have got the following XML document:
>> <foo name="something">
>> <content>abc</content>
>> <a><b>as</b></a>
>> </foo>
>>
>> And I want to unmarshall it to this class:
>> @XmlRootElement
>> public class Foo
>> @XmlAttribute(name = "name")
>> String name;
>> @XmlElement(name = "b")
>> String b;
>> }
>>
>> This is done by following code:
>> JAXBContext context = JAXBContext.newInstance(Foo.class);
>> Unmarshaller un = context.createUnmarshaller();
>> Foo foo = (Foo) un.unmarshal(new File("./data/foo.xml"));
>> System.out.println(foo.name);
>> System.out.println(foo.b);
>>
>> When this code runs foo.name is set to "something", but b isn't set to "as"?
>> What do I have to do to make this example running?
>>
>
> Try:
>
> @XmlElementWrapper(name="a")
> @XmlElement(name="b")
> String b;
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>