[Simple-support] Deserialization of type Calendar?
Brought to you by:
niallg
|
From: Timo R. <cr...@ol...> - 2008-10-01 13:36:53
|
Hello,
I can use Simple to serialize my model class, which holds a field of
type Calendar. But I'm unable to deserialize it, Simple produces this
Exception:
--------------------------
Exception in thread "main" org.simpleframework.xml.transform.TransformException: Transform of class java.util.Calendar not supported
at org.simpleframework.xml.transform.PackageMatcher.matchUtility(PackageMatcher.java:184)
at org.simpleframework.xml.transform.PackageMatcher.match(PackageMatcher.java:77)
at org.simpleframework.xml.transform.DefaultMatcher.matchType(DefaultMatcher.java:111)
at org.simpleframework.xml.transform.DefaultMatcher.match(DefaultMatcher.java:90)
...
...
--------------------------
This is my simple test class that produces the exception:
--------------------------
public class CalendarSerializationTest {
public CalendarSerializationTest() throws Exception {
// Create test model
CalendarSerializationTestModel model = new CalendarSerializationTestModel();
model.setTime( Calendar.getInstance() );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Serialization
// The method "SerializerFactory.getInstance( true )" just
// creates a new Persister object with a cycle strategy
Serializer serializer = SerializerFactory.getInstance( true );
serializer.write( model, baos );
String xml = baos.toString( "UTF-8" );
System.out.println( xml );
// Deserialization
CalendarSerializationTestModel modelDeserialized =
serializer.read( CalendarSerializationTestModel.class, xml );
}
public static void main( String[] args ) throws Exception {
new CalendarSerializationTest();
}
}
--------------------------
The class CalendarSerializationTestModel is a very simple class:
--------------------------
@Root
public class CalendarSerializationTestModel {
@Element
private Calendar time;
// [...] Getter and setter methods for "time"
}
--------------------------
The test class produces this XML code:
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<calendarSerializationTestModel xid="0">
<time class="java.util.GregorianCalendar" xid="1">2008-10-01 14:59:43.109 CEST</time>
</calendarSerializationTestModel>
--------------------------
Am I doing anything wrong? What is the reason, that Simple is able to
serialize, but unable to deserialize the type Calendar?
Thanks a lot for your help!
Best regards,
Timo Rumland
|