svn commit: r1087883 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1087883 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java

jleroux@apache.org
Author: jleroux
Date: Fri Apr  1 20:22:46 2011
New Revision: 1087883

URL: http://svn.apache.org/viewvc?rev=1087883&view=rev
Log:
Better handling of the sql-timestamp case (follow ISO format by default)

sql-Timestamp is defined as xsd:dateTime in ModelService.getTypes(), so try to parse the value as xsd:dateTime first.  
Fallback is java.sql.Timestamp because it has been this way before.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java?rev=1087883&r1=1087882&r2=1087883&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java Fri Apr  1 20:22:46 2011
@@ -26,6 +26,7 @@ import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -41,6 +42,7 @@ import java.util.TreeSet;
 import java.util.Vector;
 import java.util.WeakHashMap;
 
+import javax.xml.bind.DatatypeConverter;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.ofbiz.base.util.UtilGenerics;
@@ -318,7 +320,19 @@ public class XmlSerializer {
             // - SQL Objects -
             if ("sql-Timestamp".equals(tagName)) {
                 String valStr = element.getAttribute("value");
-                return java.sql.Timestamp.valueOf(valStr);
+                /*
+                 * sql-Timestamp is defined as xsd:dateTime in ModelService.getTypes(),
+                 * so try to parse the value as xsd:dateTime first.
+                 * Fallback is java.sql.Timestamp because it has been this way all the time.
+                 */
+                try {
+                    Calendar cal = DatatypeConverter.parseDate(valStr);
+                    return new java.sql.Timestamp(cal.getTimeInMillis());
+                }
+                catch (Exception e) {
+                    Debug.logWarning("sql-Timestamp does not conform to XML Schema definition, try java.sql.Timestamp format", module);
+                    return java.sql.Timestamp.valueOf(valStr);
+                }
             } else if ("sql-Date".equals(tagName)) {
                 String valStr = element.getAttribute("value");
                 return java.sql.Date.valueOf(valStr);
@@ -469,4 +483,4 @@ public class XmlSerializer {
         }
         return formatter;
     }
-}
+}
\ No newline at end of file