diff options
Diffstat (limited to '')
4 files changed, 22 insertions, 19 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF index f5b74a2ae7..806252650a 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF @@ -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,
diff --git a/sca-java-2.x/trunk/modules/databinding-json/pom.xml b/sca-java-2.x/trunk/modules/databinding-json/pom.xml index b81bedacd2..233e674432 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/pom.xml +++ b/sca-java-2.x/trunk/modules/databinding-json/pom.xml @@ -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> diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java index c7ae9d636d..c1afd85d00 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java +++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2Object.java @@ -27,14 +27,13 @@ import org.apache.tuscany.sca.databinding.json.JSONDataBinding; 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 PullTransformer<Object, Object> { 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 PullTransformer<Object, Object> { 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 { diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java index efe0bf7560..fc9f4aed76 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java +++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java @@ -39,9 +39,10 @@ import org.codehaus.jackson.map.DeserializationConfig; 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); |