tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1238014 - in /tuscany/sca-java-2.x/trunk: distribution/all/src/main/release/bin/ modules/databinding-json/ modules/databinding-json/META-INF/ modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/
Date Mon, 30 Jan 2012 21:10:21 GMT
Author: rfeng
Date: Mon Jan 30 21:10:20 2012
New Revision: 1238014

URL: http://svn.apache.org/viewvc?rev=1238014&view=rev
Log:
Fix the json deserialization of generic collection and upgrade to jackson 1.9.4

Modified:
    tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE
    tuscany/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF
    tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml
    tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java
    tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java

Modified: tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE?rev=1238014&r1=1238013&r2=1238014&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE (original)
+++ tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE Mon Jan 30 21:10:20
2012
@@ -261,9 +261,9 @@ The following components come under Apac
  hazelcast-client-1.9.2.2.jar
  httpclient-4.1.2.jar
  httpcore-4.1.3.jar
- jackson-core-asl-1.8.5.jar
- jackson-mapper-asl-1.8.5.jar
- jackson-xc-1.8.5.jar
+ jackson-core-asl-1.9.4.jar
+ jackson-mapper-asl-1.9.4.jar
+ jackson-xc-1.9.4.jar
  jackson-module-json-org-0.9.1.jar
  jettison-1.2.jar
  jetty-6.1.26.jar

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=1238014&r1=1238013&r2=1238014&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 Mon Jan 30 21:10:20
2012
@@ -25,6 +25,7 @@ Import-Package: javax.xml.namespace,
  org.codehaus.jackson.map.annotate,
  org.codehaus.jackson.map.deser,
  org.codehaus.jackson.map.introspect,
+ org.codehaus.jackson.map.module,
  org.codehaus.jackson.map.ser,
  org.codehaus.jackson.map.type,
  org.codehaus.jackson.map.util,

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml?rev=1238014&r1=1238013&r2=1238014&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml Mon Jan 30 21:10:20 2012
@@ -40,17 +40,17 @@
         <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-core-asl</artifactId>
-            <version>1.8.5</version>
+            <version>1.9.4</version>
         </dependency>
         <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-mapper-asl</artifactId>
-            <version>1.8.5</version>
+            <version>1.9.4</version>
         </dependency>
         <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-xc</artifactId>
-            <version>1.8.5</version>
+            <version>1.9.4</version>
         </dependency>
         
         <dependency>

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.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/JSON2Object.java?rev=1238014&r1=1238013&r2=1238014&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java
Mon Jan 30 21:10:20 2012
@@ -27,14 +27,13 @@ import org.apache.tuscany.sca.databindin
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.JsonParser;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.type.TypeFactory;
 import org.codehaus.jackson.type.JavaType;
 
 /**
  * @version $Rev$ $Date$
  */
 public class JSON2Object implements PullTransformer<Object, Object> {
-    private ObjectMapper mapper;
+    // private ObjectMapper mapper;
 
     public JSON2Object() {
         super();
@@ -48,7 +47,7 @@ public class JSON2Object implements Pull
         try {
             Class<?> cls = context.getTargetDataType().getPhysical();
             ObjectMapper mapper = JacksonHelper.createObjectMapper(cls);
-            JavaType javaType = TypeFactory.type(context.getTargetDataType().getGenericType());
+            JavaType javaType = mapper.constructType(context.getTargetDataType().getGenericType());
             if (source instanceof String) {
             	String sourceString = (String) source;
             	if(sourceString.isEmpty()) {
@@ -57,7 +56,7 @@ public class JSON2Object implements Pull
             		return mapper.readValue((String)source, javaType);
             	}
             } else if (source instanceof JsonNode) {
-                return mapper.treeToValue((JsonNode)source, context.getTargetDataType().getPhysical());
+                return mapper.readValue((JsonNode)source, javaType);
             } else if (source instanceof JsonParser) {
                 return mapper.readValue((JsonParser)source, javaType);
             } else {

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=1238014&r1=1238013&r2=1238014&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
Mon Jan 30 21:10:20 2012
@@ -39,9 +39,10 @@ import org.codehaus.jackson.map.Deserial
 import org.codehaus.jackson.map.MappingJsonFactory;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.deser.CustomDeserializerFactory;
+import org.codehaus.jackson.map.deser.BeanDeserializerFactory;
 import org.codehaus.jackson.map.deser.StdDeserializerProvider;
 import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
+import org.codehaus.jackson.map.module.SimpleDeserializers;
 import org.codehaus.jackson.map.ser.CustomSerializerFactory;
 import org.codehaus.jackson.map.util.StdDateFormat;
 import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
@@ -72,7 +73,7 @@ public class JacksonHelper {
                 XmlJavaTypeAdapters adapters = pkg.getAnnotation(XmlJavaTypeAdapters.class);
                 if (adapters != null) {
                     CustomSerializerFactory serializerFactory = new CustomSerializerFactory();
-                    CustomDeserializerFactory deserializerFactory = new CustomDeserializerFactory();
+                    BeanDeserializerFactory deserializerFactory = new BeanDeserializerFactory(null);
                     for (XmlJavaTypeAdapter a : adapters.value()) {
                         XmlAdapter xmlAdapter = null;
                         try {
@@ -81,9 +82,11 @@ public class JacksonHelper {
                             // Ignore
                         }
                         if (xmlAdapter != null) {
-                            XmlAdapterJsonDeserializer deserializer = new XmlAdapterJsonDeserializer(xmlAdapter,
null);
-                            XmlAdapterJsonSerializer serializer = new XmlAdapterJsonSerializer(xmlAdapter,
null);
-                            deserializerFactory.addSpecificMapping(a.type(), deserializer);
+                            XmlAdapterJsonDeserializer deserializer = new XmlAdapterJsonDeserializer(xmlAdapter);
+                            XmlAdapterJsonSerializer serializer = new XmlAdapterJsonSerializer(xmlAdapter);
+                            SimpleDeserializers deserializers = new SimpleDeserializers();
+                            deserializers.addDeserializer(a.type(), deserializer);
+                            deserializerFactory.withAdditionalDeserializers(deserializers);
                             serializerFactory.addGenericMapping(a.type(), serializer);
                             StdDeserializerProvider deserializerProvider =
                                 new StdDeserializerProvider(deserializerFactory);
@@ -104,12 +107,12 @@ public class JacksonHelper {
         AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
         AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
         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());
+        mapper.setDeserializationConfig(mapper.getDeserializationConfig().withAnnotationIntrospector(pair)
+            .without(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)
+            .withDateFormat(StdDateFormat.getBlueprintISO8601Format()));
+        mapper.setSerializationConfig(mapper.getSerializationConfig().withAnnotationIntrospector(pair)
+            .withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL)
+            .withDateFormat(StdDateFormat.getBlueprintISO8601Format()));
         return mapper;
     }
 
@@ -214,7 +217,7 @@ public class JacksonHelper {
             throw new IOException(e);
         }
     }
-    
+
     public static String write(JSONObject json) throws IOException {
         try {
             return MAPPER.writeValueAsString(json);



Mime
View raw message