Uploaded image for project: 'JBoss Marshalling'
  1. JBoss Marshalling
  2. JBMAR-233

Cannot cast java.util.TreeMap to java.util.Date , if Date field name sorts after Map

XMLWordPrintable

    • Hide

      java -cp $JBOSS_HOME/bin/client/jboss-client.jar:JBMAR-233.jar WriteReadExample

      Show
      java -cp $JBOSS_HOME/bin/client/jboss-client.jar: JBMAR-233 .jar WriteReadExample
    • Workaround Exists
    • Hide

      Change Collections.emptySortedMap() to new TreeMap<String,String>();

      Change from :
      
        private SortedMap<String, String> map = Collections.emptySortedMap();
        private Date mop; 
      
      to:
      
        private SortedMap<String, String> map = new TreeMap<String,String>();
        private Date mop; 

       

      Or use MarshallingConfiguration version 3

            final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("river");
       
              // Create a configuration
              final MarshallingConfiguration configuration = new MarshallingConfiguration();
              // Use version 3
              configuration.setVersion(3);
      Show
      Change Collections.emptySortedMap() to new TreeMap<String,String>(); Change from :   private SortedMap< String , String > map = Collections.emptySortedMap();   private Date mop; to:   private SortedMap< String , String > map = new TreeMap< String , String >();   private Date mop;   Or use MarshallingConfiguration version 3     final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory( "river" );           // Create a configuration         final MarshallingConfiguration configuration = new MarshallingConfiguration();         // Use version 3         configuration.setVersion(3);
    • Undefined

       

       

           [java] Exception in thread "main" java.lang.ClassCastException: Cannot cast java.util.TreeMap to java.util.Date
           [java] 	at java.lang.Class.cast(Class.java:3369)
           [java] 	at org.jboss.marshalling.reflect.SerializableField.setObject(SerializableField.java:342)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1864)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1778)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1406)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:283)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:231)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1864)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1778)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1406)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:283)
           [java] 	at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:216)
           [java] 	at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
           [java] 	at WriteReadExample.read(WriteReadExample.java:90)
           [java] 	at WriteReadExample.main(WriteReadExample.java:27)
           [java] Caused by: an exception which occurred:
           [java] 	in field Wrapper.mop
           [java] 	in object Wrapper@5faeada1
           [java] 	in object of type Wrapper
           [java] 	in field SortedMapIn.to
           [java] 	in object SortedMapIn@528931cf
           [java] 	in object of type SortedMapIn 

              dlloyd@redhat.com David Lloyd
              rhn-support-bmaxwell Brad Maxwell
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: