tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1165872 - in /tuscany/sca-java-2.x/trunk/modules/databinding-json: META-INF/ src/main/java/org/apache/tuscany/sca/databinding/json/jackson/ src/test/java/org/apache/tuscany/sca/databinding/json/jackson/
Date Tue, 06 Sep 2011 21:45:25 GMT
Author: rfeng
Date: Tue Sep  6 21:45:25 2011
New Revision: 1165872

URL: http://svn.apache.org/viewvc?rev=1165872&view=rev
Log:
Fix the Date format for json data binding

Modified:
    tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF
    tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
    tuscany/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSONTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF?rev=1165872&r1=1165871&r2=1165872&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF Tue Sep  6 21:45:25
2011
@@ -26,6 +26,7 @@ Import-Package: javax.xml.namespace,
  org.codehaus.jackson.map.introspect,
  org.codehaus.jackson.map.ser,
  org.codehaus.jackson.map.type,
+ org.codehaus.jackson.map.util,
  org.codehaus.jackson.type,
  org.codehaus.jackson.xc;resolution:=optional,
  org.codehaus.jettison.badgerfish,

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java?rev=1165872&r1=1165871&r2=1165872&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
Tue Sep  6 21:45:25 2011
@@ -43,6 +43,7 @@ import org.codehaus.jackson.map.deser.Cu
 import org.codehaus.jackson.map.deser.StdDeserializerProvider;
 import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
 import org.codehaus.jackson.map.ser.CustomSerializerFactory;
+import org.codehaus.jackson.map.util.StdDateFormat;
 import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
 import org.codehaus.jackson.xc.XmlAdapterJsonDeserializer;
 import org.codehaus.jackson.xc.XmlAdapterJsonSerializer;
@@ -99,8 +100,10 @@ public class JacksonHelper {
         AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
         mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
         mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
Boolean.FALSE);
+        mapper.getDeserializationConfig().setDateFormat(StdDateFormat.getBlueprintISO8601Format());
         mapper.getSerializationConfig().setAnnotationIntrospector(pair);
         mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+        mapper.getSerializationConfig().setDateFormat(StdDateFormat.getBlueprintISO8601Format());
         return mapper;
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSONTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSONTestCase.java?rev=1165872&r1=1165871&r2=1165872&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSONTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSONTestCase.java
Tue Sep  6 21:45:25 2011
@@ -20,6 +20,8 @@
 package org.apache.tuscany.sca.databinding.json.jackson;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 import junit.framework.Assert;
@@ -41,6 +43,7 @@ public class Object2JSONTestCase {
         private String friends[];
         private List<String> books;
         private YourBean you;
+        private Date date;
 
         public String getName() {
             return name;
@@ -90,6 +93,80 @@ public class Object2JSONTestCase {
             this.you = you;
         }
 
+        public Date getDate() {
+            return date;
+        }
+
+        public void setDate(Date date) {
+            this.date = date;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + age;
+            result = prime * result + ((books == null) ? 0 : books.hashCode());
+            result = prime * result + ((date == null) ? 0 : date.hashCode());
+            result = prime * result + Arrays.hashCode(friends);
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            result = prime * result + (vip ? 1231 : 1237);
+            result = prime * result + ((you == null) ? 0 : you.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            MyBean other = (MyBean)obj;
+            if (age != other.age) {
+                return false;
+            }
+            if (books == null) {
+                if (other.books != null) {
+                    return false;
+                }
+            } else if (!books.equals(other.books)) {
+                return false;
+            }
+            if (date == null) {
+                if (other.date != null) {
+                    return false;
+                }
+            } else if (!date.equals(other.date)) {
+                return false;
+            }
+            if (!Arrays.equals(friends, other.friends)) {
+                return false;
+            }
+            if (name == null) {
+                if (other.name != null) {
+                    return false;
+                }
+            } else if (!name.equals(other.name)) {
+                return false;
+            }
+            if (vip != other.vip) {
+                return false;
+            }
+            if (you == null) {
+                if (other.you != null) {
+                    return false;
+                }
+            } else if (!you.equals(other.you)) {
+                return false;
+            }
+            return true;
+        }
+
     }
 
     public static class YourBean {
@@ -111,6 +188,40 @@ public class Object2JSONTestCase {
         public void setName(String name) {
             this.name = name;
         }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + id;
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            YourBean other = (YourBean)obj;
+            if (id != other.id) {
+                return false;
+            }
+            if (name == null) {
+                if (other.name != null) {
+                    return false;
+                }
+            } else if (!name.equals(other.name)) {
+                return false;
+            }
+            return true;
+        }
     }
 
     @Test
@@ -121,6 +232,7 @@ public class Object2JSONTestCase {
         me.setFriends(new String[] {"John", "Mike"});
         me.setVip(true);
         me.setName("Me");
+        me.setDate(new Date());
         YourBean you = new YourBean();
         you.setId(123);
         you.setName(null);
@@ -136,6 +248,7 @@ public class Object2JSONTestCase {
         //        String json =
         //            "{\"age\":30,\"books\":[],\"friends\":[\"John\",\"Mike\"],\"name\":\"Me\",\"vip\":true,\"you\":{\"id\":123,\"name\":null}}";
         //        Assert.assertEquals(json, result.toString());
+        Assert.assertEquals(v, me);
     }
 
     @Test



Mime
View raw message