Re: [Simple-support] ElementMap question
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-06-24 17:16:26
|
Hi,
Have a look at the Dictionary class in org.simpleframework.xml.util. This looks like what you want. In order to use attributes in the value it has to be a sub-element of the entry and can not go in the entry element. For example:
<entry key="key>
<value a="a" b="b" c="c"/>
</entry>
In order to get a flat list you will need to use an ElementList. The Dictionary (which is a HashSet) object can make use of an attribute to do this. It has a get() method. If you want you can use an ElementList and transfer this via some key to a map using the @Commit annotation like so.
public class MyClass {
@ElementList(inline=true)
private List<Foo> list;
private Map<Integer, Foo> map;
@Commit
private void commit() {
for(Foo foo : list) {
map.put(foo.level, foo);
}
}
}
Hope this helps.
Niall
--- On Mon, 6/23/08, Micah Jaffe <mi...@af...> wrote:
> From: Micah Jaffe <mi...@af...>
> Subject: [Simple-support] ElementMap question
> To: sim...@li...
> Date: Monday, June 23, 2008, 2:37 PM
> I have an ElementMap that I'm declaring as such:
>
> @ElementMap(entry="foo", key="level",
> attribute=true, inline=true)
> private HashMap<Integer, Foo> map = new
> HashMap<Integer, Foo>();
>
> private static class Foo
> {
> @Attribute(required=false)
> private String attr1;
>
> @Attribute(required=false)
> private String attr2;
>
> @Text
> private String value;
> }
>
> The goal would be to be able to read XML like this:
>
> <foo level="0"
> attr1="abc">value1</foo>
> <foo level="1"
> attr2="xyz">value2</foo>
> <foo level="3"
> attr1="123">value3</foo>
>
> When testing the code it seems to pull out the key
> information
> correctly, but is setting every value of Foo in the HashMap
> to null.
> The goal is to be able to retrieve an object from this map
> that will
> always be keyed off "level", and have N number of
> attributes (meta
> data) which are optional, and only a single value.
>
> What am I doing wrong?
>
> -Micah
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|