Sorry if I was too brief, but I don't have a class for FriendList, it's just
a List<String> attribute inside a class. Like:
public class MyClass{
private List<String> friendList = null;
//getters and setters
}
So the <friendList> tag is just a "wrapper" (I can use the XmlElementWrapper
there to make it work), and I get the correct number of elements in my list
after unmarshalling, but they are all null (I think because it does not
understand that the String has to come from the value attribute).
I can make it work if the XML is like this:
<friendList>
<friend>Fred</name>
<!-- instead of
<friend value="Fred" />
-->
</friendList>
Any Ideas?
Wolfgang Laun-2 wrote:
>
> @XmlType
> class FriendsList {
> @XmlElement
> List<String> friend;
> }
>
> That's all you need.
> -WL
>
> On Thu, Nov 27, 2008 at 11:27 PM, anbernas
> <andres.bernasconi_at_gmail.com>wrote:
>
>>
>> Hi, I have the following XML (snippet)
>>
>> ...
>> <friendsList>
>> <friend name="Fred"/>
>> <friend name="Walter"/>
>> ...
>> </friendsList>
>>
>> And I want to map that structure to a List<String> (where each element in
>> the list should be "Fred", "Walter", etc.) I would like to try to avoid
>> creating and intermediate class for Friend that only contains a name. I
>> am
>> also using annotations for this, so I would like to stick to that.
>>
>> Is there any way to do it?
>>
>> I tried the following but I don't understand where I am supposed to
>> specify
>> the attribute of the element:
>> @XmlElementWrapper(name="friendsList")
>> @XmlElement(name="friend")
>> //_at_XmlAttribute(name="name") <-- both element and attribute are invalid
>> protected List<String> friendList;
>>
>> Thank you very much for your time!
>> Regards
>> AB.
>> --
>> View this message in context:
>> http://www.nabble.com/Help-needed-mapping-a-collection-of-Strings-to-an-element-with-attribute-tp20726382p20726382.html
>> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Help-needed-mapping-a-collection-of-Strings-to-an-element-with-attribute-tp20726382p20730247.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.