[Simple-support] @ElementMap
Brought to you by:
niallg
|
From: <jo...@va...> - 2012-11-28 14:51:36
|
----- Forwarded message -----
From: "van Waasen Jochen (KFSC 11)" <joc...@cr...>
To: <sim...@li...>
Cc: <jo...@va...>
Subject: @ElementMap
Date: Wed, Nov 28, 2012 15:17
Hi, I am new to simpleXML and stuck with @ElementMap. I would like to parse the following: <?xml version="1.0" encoding="UTF-8"?><plist version="1.5"> <dict> <key>key01</key><string>value01</string> <key>key02</key><string>value02</string> <key>key03</key><string>value03</string> </dict></plist> My class looks like this: import java.util.Map; import org.simpleframework.xml.Attribute;import org.simpleframework.xml.ElementMap;import org.simpleframework.xml.Root; @Root(name = "plist")public class PropertyList{ @ElementMap(name = "dict", key="key", keyType=String.class, value="string", valueType=String.class, required=false, inline=false) private Map<String, String> plDictionary; @Attribute(required = true) private String version; public String getVersion(){ return this.version; } public Map<String, String> getMap(){ return this.plDictionary; } public void setMap(Map<String, String> theMap){ this.plDictionary = theMap; }} As a result I get a Map which contains another Map with null values.I would expect only ONE Map to be created. If I change the XML to this:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.5"> <dict> <dict> <key>key01</key><string>value01</string> <key>key02</key><string>value02</string> <key>key03</key><string>value03</string></dict> </dict></plist> Then the Map inside the Map has the values. What is wrong in my config? I just want to have ONE Map that holds these values.How can this be achieved? ThanksJochen |