tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1148839 - in /tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main: java/org/apache/tuscany/sca/databinding/json/jackson/ resources/META-INF/services/
Date Wed, 20 Jul 2011 16:41:01 GMT
Author: rfeng
Date: Wed Jul 20 16:41:00 2011
New Revision: 1148839

URL: http://svn.apache.org/viewvc?rev=1148839&view=rev
Log:
Streamline the json serialization into output stream

Modified:
    tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
    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/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.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/JSON2OutputStream.java?rev=1148839&r1=1148838&r2=1148839&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
Wed Jul 20 16:41:00 2011
@@ -27,6 +27,9 @@ import org.apache.tuscany.sca.databindin
 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.json.JSONArray;
+import org.json.JSONObject;
 
 /**
  * 
@@ -50,10 +53,22 @@ public class JSON2OutputStream implement
         } else if (source instanceof JsonParser) {
             JacksonHelper.write((JsonParser)source, sink);
         } else {
-            try {
-                sink.write(source.toString().getBytes("UTF-8"));
-            } catch (Exception e) {
-                throw new TransformationException(e);
+            if (source instanceof String || source instanceof JSONObject
+                || source instanceof JSONArray
+                || source instanceof org.codehaus.jettison.json.JSONObject
+                || source instanceof org.codehaus.jettison.json.JSONArray) {
+                try {
+                    sink.write(source.toString().getBytes("UTF-8"));
+                } catch (Exception e) {
+                    throw new TransformationException(e);
+                }
+            } else {
+                ObjectMapper mapper = JacksonHelper.createObjectMapper(source.getClass());
+                try {
+                    mapper.writeValue(sink, source);
+                } catch (Throwable e) {
+                    throw new TransformationException(e);
+                }
             }
         }
     }

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=1148839&r1=1148838&r2=1148839&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
Wed Jul 20 16:41:00 2011
@@ -98,7 +98,6 @@ public class JacksonHelper {
         AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
         AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
         mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
-        // [rfeng] To avoid complaints about javaClass
         mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
Boolean.FALSE);
         mapper.getSerializationConfig().setAnnotationIntrospector(pair);
         mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer?rev=1148839&r1=1148838&r2=1148839&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
Wed Jul 20 16:41:00 2011
@@ -15,3 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 org.apache.tuscany.sca.databinding.json.jackson.JSON2OutputStream;source=JSON;target=application/json#java.io.OutputStream,weight=50,public=true
+org.apache.tuscany.sca.databinding.json.jackson.JSON2OutputStream;source=javax.xml.bind.JAXBElement;target=application/json#java.io.OutputStream,weight=50,public=true
+org.apache.tuscany.sca.databinding.json.jackson.JSON2OutputStream;source=java:complexType;target=application/json#java.io.OutputStream,weight=50,public=true
+org.apache.tuscany.sca.databinding.json.jackson.JSON2OutputStream;source=java:simpleType;target=application/json#java.io.OutputStream,weight=50,public=true



Mime
View raw message