Re: [Simple-support] Transform exception on enum in ElementMap
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2009-05-22 14:17:56
|
Hi Greg,
Thanks for the feedback, ill take a look in to this.
Niall
--- On Sat, 5/16/09, Greg Cottman <gre...@qu...> wrote:
> From: Greg Cottman <gre...@qu...>
> Subject: [Simple-support] Transform exception on enum in ElementMap
> To: "sim...@li..." <sim...@li...>
> Date: Saturday, May 16, 2009, 3:13 AM
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hi
> Niall,
>
>
>
>
> I
> am using Simple XML 2.0.4 with Java 1.6.0_04 in a Windows
> XP environment.
>
>
>
>
> I
> have a test program:
>
>
>
>
> package test;
>
>
>
>
> import java.io.File;
>
> import
> java.util.HashMap;
>
> import java.util.Map;
>
>
>
>
> import
> org.simpleframework.xml.ElementMap;
>
> import
> org.simpleframework.xml.Root;
>
> import
> org.simpleframework.xml.Serializer;
>
> import
> org.simpleframework.xml.core.Persister;
>
>
>
>
> public enum Example
>
> {
>
> CAT,
>
> DOG,
>
> FERRET;
>
>
>
>
> public static void main( String[] args
> )
>
> {
>
>
> try
>
>
> {
>
>
> TestExample test = new TestExample();
>
>
> for ( Example x :
> Example.values() )
>
>
> test.add( x );
>
>
>
>
>
> File file = new File( "example.xml" );
>
>
> Serializer s = new Persister();
>
>
> s.write( test, file );
>
>
>
>
>
> test = s.read( TestExample.class, file );
>
>
> }
>
>
> catch( Exception e )
>
>
> {
>
>
> e.printStackTrace();
>
>
> }
>
> }
>
> }
>
>
>
>
> @Root
>
> class TestExample
>
> {
>
> @ElementMap( keyType =
> String.class, valueType = Object.class )
>
> public
> Map<String,Object> objectMap = new
> HashMap<String,Object>();
>
>
>
>
> @ElementMap( keyType =
> String.class, valueType = Example.class )
>
> public
> Map<String,Example> enumMap = new
> HashMap<String,Example>();
>
>
>
>
> public void add( Example x
> )
>
> {
>
>
> objectMap.put( x.name(),
> x );
>
>
> enumMap.put( x.name(),
> x );
>
> }
>
> }
>
>
>
>
> That
> generates this XML:
>
>
>
>
> <testExample>
>
> <objectMap
> class="java.util.HashMap">
>
>
> <entry>
>
>
> <string>CAT</string>
>
>
> <object
> class="test.Example">CAT</object>
>
>
>
> </entry>
>
>
> <entry>
>
>
> <string>FERRET</string>
>
>
> <object
> class="test.Example">FERRET</object>
>
>
>
> </entry>
>
>
> <entry>
>
>
> <string>DOG</string>
>
>
> <object
> class="test.Example">DOG</object>
>
>
>
> </entry>
>
>
> </objectMap>
>
> <enumMap
> class="java.util.HashMap">
>
>
> <entry>
>
>
> <string>CAT</string>
>
>
> <example>CAT</example>
>
>
> </entry>
>
>
> <entry>
>
>
> <string>FERRET</string>
>
>
> <example>FERRET</example>
>
>
> </entry>
>
>
> <entry>
>
>
> <string>DOG</string>
>
>
> <example>DOG</example>
>
>
> </entry>
>
>
> </enumMap>
>
> </testExample>
>
>
>
>
> The
> problem is that while both map elements can be serialised,
> only the enumMap
> element can be deserialised. The objectMap element
> will throw this
> TransformException:
>
>
>
>
> org.simpleframework.xml.transform.TransformException: Transform of
> class com.kaiz.darms.configuration.Example not
> supported
>
>
> at
> org.simpleframework.xml.transform.Transformer.read(Transformer.java:104)
>
>
> at
> org.simpleframework.xml.core.Support.read(Support.java:176)
>
>
> at
> org.simpleframework.xml.core.PrimitiveFactory.getInstance(PrimitiveFactory.java:110)
>
>
> at
> org.simpleframework.xml.core.Primitive.readTemplate(Primitive.java:225)
>
>
> at
> org.simpleframework.xml.core.Primitive.read(Primitive.java:166)
>
>
> at
> org.simpleframework.xml.core.Composite.readPrimitive(Composite.java:178)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:133)
>
>
> at
> org.simpleframework.xml.core.Traverser.read(Traverser.java:78)
>
>
> at
> org.simpleframework.xml.core.CompositeValue.read(CompositeValue.java:102)
>
>
> at
> org.simpleframework.xml.core.CompositeMap.populate(CompositeMap.java:177)
>
>
> at
> org.simpleframework.xml.core.CompositeMap.read(CompositeMap.java:148)
>
>
> at
> org.simpleframework.xml.core.Composite.readObject(Composite.java:517)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:477)
>
>
> at
> org.simpleframework.xml.core.Composite.readElement(Composite.java:458)
>
>
> at
> org.simpleframework.xml.core.Composite.readElements(Composite.java:374)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:259)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:204)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:158)
>
>
> at
> org.simpleframework.xml.core.Composite.read(Composite.java:135)
>
>
> at
> org.simpleframework.xml.core.Traverser.read(Traverser.java:78)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:544)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:526)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:507)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:489)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:471)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:452)
>
>
> at
> org.simpleframework.xml.core.Persister.read(Persister.java:431)
>
>
> at
> com.kaiz.darms.configuration.Example.main(Example.java:30)
>
>
>
>
> I
> did try adding a @Root annotation to the Example
> class. This stopped
> Simple throwing an exception but the deserialised objectMap
> had null for each value.
>
>
>
>
> Cheers,
>
> Greg.
>
>
>
> Greg Cottman
>
> Tel: +61 419
> 535 485
>
> mailto:Gre...@qu...
>
>
>
>
>
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> ------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd,
> NYC. CaT
> is a gathering of tech-side developers & brand
> creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity,
> Processing, &
> iPhoneDevCamp asthey present alongside digital heavyweights
> like Barbarian
> Group, R/GA, & Big Spaceship. http://www.creativitycat.com
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
|