|
[xstream-dev] [jira] Closed: (XSTR-86) Cannot correctly convert Calendar cl: msg#00021java.xstream.devel
Message: The following issue has been closed. --------------------------------------------------------------------- View the issue: http://jira.codehaus.org/browse/XSTR-86 Here is an overview of the issue: --------------------------------------------------------------------- Key: XSTR-86 Summary: Cannot correctly convert Calendar classes Type: Bug Status: Closed Priority: Major Resolution: FIXED Original Estimate: 10 minutes Time Spent: Unknown Remaining: 10 minutes Project: XStream Components: Converters Fix Fors: 1.0.2 Versions: 1.0.1 Assignee: Reporter: Neil Clayton Created: Sun, 13 Jun 2004 3:35 PM Updated: Sat, 24 Jul 2004 3:48 PM Environment: JDK 1.5 or 1.4 Description: 1.0.1 does not correctly handle the serialization and deserialization of Calendar instances. This is probably because they declare some member variables without initializers, and rely on the constructors providing good values ... I've provided a test case and converter to solve the problem, but there may be a more elegant solution. The supplied converter simply uses a DateConverter to perform the work. TestCase ========= public void testCalendarCanBeReconstructed() { Calendar cal = Calendar.getInstance(); XStream stream = new XStream(); String serializedCal = stream.toXML(cal); Calendar newCal = (Calendar) stream.fromXML(serializedCal); assertEquals(cal, newCal); System.out.println("serializedCal = " + serializedCal); System.out.println("newCal = " + newCal); // This will cause an NPE } Fix ======= public class CalendarConverter extends AbstractBasicConverter { private DateConverter dateConverter = new DateConverter(); public boolean canConvert(Class type) { return Calendar.class.isAssignableFrom(type); } protected Object fromString(String str) { Date date = (Date) dateConverter.fromString(str); Calendar instance = Calendar.getInstance(); instance.setTime(date); return instance; } protected String toString(Object obj) { Calendar cal = (Calendar) obj; return dateConverter.toString(cal.getTime()); } } Obviously, an addition to the DefaultConverterLookup is also required. ~Neil --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [xstream-dev] [jira] Created: (XSTR-102) Doesn't work with MultiHashMap, jira-yCVjj/EcxBJg9hUCZPvPmw |
|---|---|
| Next by Date: | [xstream-dev] [jira] Closed: (XSTR-97) Duplicate elements should cause an exception, jira-yCVjj/EcxBJg9hUCZPvPmw |
| Previous by Thread: | [xstream-dev] [jira] Created: (XSTR-102) Doesn't work with MultiHashMap, jira-yCVjj/EcxBJg9hUCZPvPmw |
| Next by Thread: | [xstream-dev] [jira] Closed: (XSTR-97) Duplicate elements should cause an exception, jira-yCVjj/EcxBJg9hUCZPvPmw |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |