[Simple-support] Question regarding maps
Brought to you by:
niallg
|
From: Timo R. <cr...@ol...> - 2008-04-12 12:49:56
|
Hello,
I have a question regarding the serialization of maps. Let's assume we
have the following two Classes:
--------------
@Root( name = "UIDefinition" )
public class UIAdapterModel {
@ElementMap(entry="UserInterface", key="key", attribute=true, inline=true )
public HashMap<String, UserInterface> userInterfaces = new HashMap<String, UserInterface>();
}
@Root
public class UserInterface {
@Element
public String identifier = null;
}
--------------
My serialization code looks like this:
--------------
Serializer serializer = new Persister();
UIAdapterModel model = new UIAdapterModel();
model.userInterfaces.put("id1", new UserInterface("id1"));
serializer.write(model, System.out);
--------------
(Note: The constructor of class "UserInterface" sets the "identifier"
member of that instance.)
What I now get the the following XML output:
<UIDefinition>
<UserInterface key="id1">
<userInterface>
<identifier>id1</identifier>
</userInterface>
</UserInterface>
</UIDefinition>
My question is now, why is there the "<userInterface>" tag? What I
wanted to have is just:
<UIDefinition>
<UserInterface key="id1">
<identifier>id1</identifier>
</UserInterface>
</UIDefinition>
When I look at your example on the tutorial page of Simple XML in the
"Dealing with map objects" section, the XML output is:
<properties>
<property key="one">first value</property>
<property key="two">second value</property>
</properties>
There is not another tag like in my output. Why is that? Perhaps
because Strings are handled somewhat different than arbitrary classes?
Is there a way to get an output without that "<userInterface>" tag?
Thanks a lot for your help!
Best regards,
Timo
|