[Simple-support] NPE using Map
Brought to you by:
niallg
|
From: <Jas...@sc...> - 2008-04-28 19:39:04
|
Hi,
Really like the looks of the library, seems very neat - but I'm having a
problem setting up.
When I run the following:
@Root
public class TestXML<Value>
{
@ElementMap
Map<String, Value> map;
TestXML()
{
map = new HashMap<String, Value>();
}
public static void main(String[] args) throws Exception
{
TestXML<Double> object = new TestXML<Double>();
object.map.put("One", 1.0);
object.map.put("Two", 2.0);
Serializer serializer = new Persister();
serializer.write(object, new File("test.xml"));
}
}
I get:
Exception in thread "main" java.lang.NullPointerException
at org.simpleframework.xml.load.Factory.isPrimitive(
Factory.java:213)
at org.simpleframework.xml.load.Entry.getValue(Entry.java:191)
at org.simpleframework.xml.load.CompositeMap.<init>(
CompositeMap.java:89)
at org.simpleframework.xml.load.ElementMapLabel.getConverter(
ElementMapLabel.java:101)
at org.simpleframework.xml.load.CacheLabel.getConverter(
CacheLabel.java:135)
at org.simpleframework.xml.load.Composite.writeElement(
Composite.java:829)
at org.simpleframework.xml.load.Composite.writeElements(
Composite.java:728)
at org.simpleframework.xml.load.Composite.write(Composite.java:666
)
at org.simpleframework.xml.load.Composite.write(Composite.java:644
)
at org.simpleframework.xml.load.Traverser.write(Traverser.java:206
)
at org.simpleframework.xml.load.Traverser.write(Traverser.java:183
)
at org.simpleframework.xml.load.Traverser.write(Traverser.java:161
)
at org.simpleframework.xml.load.Persister.write(Persister.java:769
)
at org.simpleframework.xml.load.Persister.write(Persister.java:751
)
at org.simpleframework.xml.load.Persister.write(Persister.java:732
)
at org.simpleframework.xml.load.Persister.write(Persister.java:848
)
at org.simpleframework.xml.load.Persister.write(Persister.java:830
)
at org.simpleframework.xml.load.Persister.write(Persister.java:811
)
at org.simpleframework.xml.load.Persister.write(Persister.java:790
)
at TestXML.main(TestXML.java:30)
OK, so I guess it may be generics-related. It works fine if I change the
generic Double to an explicit one. But this is a bit weird as the
implementation of Map is itself generic?!
To confuse me even more, changing this to an explicit Map<String, Object>
gives the following unusable file:
<testXML>
<map class="java.util.HashMap">
<entry>
<string>Two</string>
<object class="java.lang.Double"/>
</entry>
<entry>
<string>One</string>
<object class="java.lang.Double"/>
</entry>
</map>
</testXML>
i.e. It has lost the values of the Doubles....
Jason Chown
Sony Computer Entertainment Europe
http://www.eu.playstation.com
**********************************************************************
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify pos...@sc...
This footnote also confirms that this email message has been checked for all known viruses.
Sony Computer Entertainment Europe Limited
Registered Office: 10 Great Marlborough Street, London W1F 7LP, United Kingdom
Registered in England: 3277793
**********************************************************************
|