tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1149074 - in /tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json: ./ src/main/java/org/apache/tuscany/sca/databinding/json/jackson/ src/main/resources/META-INF/services/
Date Thu, 21 Jul 2011 08:39:08 GMT
Author: antelder
Date: Thu Jul 21 08:39:06 2011
New Revision: 1149074

URL: http://svn.apache.org/viewvc?rev=1149074&view=rev
Log:
Merge change in 1148839 to Streamline the json serialization into output stream to beta3

Modified:
    tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/   (props changed)
    tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
    tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
    tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer

Propchange: tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Jul 21 08:39:06 2011
@@ -0,0 +1,2 @@
+/tuscany/branches/sca-java-1.3/modules/databinding-json:671193
+/tuscany/sca-java-2.x/trunk/modules/databinding-json:1148839

Modified: tuscany/sca-java-2.x/branches/2.0-Beta3/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/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java?rev=1149074&r1=1149073&r2=1149074&view=diff
==============================================================================
--- tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
(original)
+++ tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
Thu Jul 21 08:39:06 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/branches/2.0-Beta3/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/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java?rev=1149074&r1=1149073&r2=1149074&view=diff
==============================================================================
--- tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
(original)
+++ tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java
Thu Jul 21 08:39:06 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/branches/2.0-Beta3/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/branches/2.0-Beta3/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer?rev=1149074&r1=1149073&r2=1149074&view=diff
==============================================================================
--- tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
(original)
+++ tuscany/sca-java-2.x/branches/2.0-Beta3/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
Thu Jul 21 08:39:06 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