Re: [Simple-support] Simple1.7.3 EnumMap deserialization bug
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-12-12 13:05:06
|
Hi,
This issue has not been resolved in 2.0.2. You can now read EnumMap and EnumSet values annotated with @ElementMap and @ElementList. However, these must be instantiated initially. For example
@ElementMap
private EnumMap<Enumeration, String> map = new EnumMap<Enumeration, String>(Enumeration.class);
This will maintain the original instance and you will not see the exception thrown in 1.7.3 where it can not instantiate the EnumMap.
Regards,
Niall
--- On Sun, 11/23/08, Niall Gallagher <gal...@ya...> wrote:
> From: Niall Gallagher <gal...@ya...>
> Subject: Re: [Simple-support] Simple1.7.3 EnumMap deserialization bug
> To: "Rob Gilson" <rob...@ar...>, sim...@li...
> Cc: "Arise" <ar...@si...>
> Date: Sunday, November 23, 2008, 1:40 AM
> Hi,
>
> The only way to do it currently would be to use an @Commit
> annotation and pass it from a Map to an EnumMap.
>
> @Commit
> public void commit() {
> enumMap.putAll(normalMap);
> }
>
> Support for EnumMap objects will be added in an upcoming
> release.
>
> Niall
>
>
>
>
> ________________________________
> From: Rob Gilson <rob...@ar...>
> To: sim...@li...
> Cc: Arise <ar...@si...>
> Sent: Saturday, November 22, 2008 8:04:39 PM
> Subject: [Simple-support] Simple1.7.3 EnumMap
> deserialization bug
>
> Hi all,
> I've been working on a project which is heavily reliant
> on the Simple xml serialization library and I seem to have
> come across a problem in it's instantiation of EnumMaps.
> As many of you undoubtedly know EnumMaps do not have a zero
> parameter constructor rather they can only be constructed by
> passing the Class of the enum you wish to use due to the
> limitation of java Generics, my problem comes about as it
> seems Simple Xml is trying to use that non-existant
> EnumMap() constructor and is throwing a
> NoSuchMethodException. The stack trace (for
> deserialization, serialization works fine), if i allow java
> to step forward into the exception is as follows:
>
>
> Exception in thread "main"
> java.lang.NoSuchMethodException:
> java.util.EnumMap.<init>()
> at java.lang.Class.getConstructor0(Unknown Source)
> at java.lang.Class.getDeclaredConstructor(Unknown
> Source)
> at
> org.simpleframework.xml.load.ClassType.getInstance(ClassType.java:88)
> at
> org.simpleframework.xml.load.ClassType.getInstance(ClassType.java:72)
> at
> org.simpleframework.xml.load.CompositeMap.read(CompositeMap.java:109)
> at
> org.simpleframework.xml.load.Composite.read(Composite.java:354)
> at
> org.simpleframework.xml.load.Composite.readElement(Composite.java:334)
> at
> org.simpleframework.xml.load.Composite.readElements(Composite.java:250)
> at
> org.simpleframework.xml.load.Composite.read(Composite.java:194)
>
> Any help would be greatly appreciated. Also I just wanted
> to say thanks to the Simple team, you guys have done an
> awsome job with Simple, its very intuitive and very
> powerfull, the combination of which has saved me massive
> amounts of time on this project!
>
> Cheers,
> Rob
>
> My source code:
>
> /**
> *
> */
> package simpleXmlSandpit;
>
> import java.io.File;
> import java.util.EnumMap;
>
> import org.simpleframework.xml.ElementMap;
> import org.simpleframework.xml.Root;
> import org.simpleframework.xml.Serializer;
> import org.simpleframework.xml.load.Persister;
>
> /**
> * @author Rob Gilson, University of Ottawa CEG Student
> */
> @Root
> public class EnumTestSerialization {
> @ElementMap (required=false) public
> EnumMap<TestEnum, String> map = new
> EnumMap<TestEnum, String>(TestEnum.class);
> public static enum TestEnum
> {
> enumTest,
> otherTest
> }
>
> public EnumTestSerialization()
> {
> map.put(TestEnum.enumTest, "hello world this
> is the test #1");
> map.put(TestEnum.otherTest, "hello world this
> is the other test #2");
> }
>
> /**
> * serializes and subsiquently deserializes a object
> containing a enum map
> * to illustrate a potential bug in Simple 1.7.3
> * @param args unused.
> * @throws Exception if the serialization or
> deserialization fail.
> */
> public static void main(String[] args) throws Exception
> {
>
> java.io.File file = new
> File("example.xml");
> Serializer serializer = new Persister();
> EnumTestSerialization example;
>
> //Serialization
> example = new EnumTestSerialization();
> serializer.write(example, file);
>
> example = null;
>
> //Deserialization
> if (file.exists() == false)
> System.err.println("File does not exist!");
> //Exception is thrown here \/
> example =
> serializer.read(EnumTestSerialization.class, file);
> //Exception is thrown here /\
>
> System.out.println(example.map.get(TestEnum.enumTest));
>
> System.exit(1);
> }
>
> }
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move
> Developer's challenge
> Build the coolest Linux based applications with Moblin SDK
> & win great prizes
> Grand prize is a trip for two to an Open Source event
> anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|