summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java23
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java1
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer3
3 files changed, 22 insertions, 5 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
index 920485a540..cb76f74baa 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java
@@ -27,6 +27,9 @@ import org.apache.tuscany.sca.databinding.TransformationException;
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 implements PushTransformer<Object, OutputStream>
} 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);
+ }
}
}
}
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 e684378c6e..895c9e70ce 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
@@ -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);
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer b/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
index c3272d1425..f880719ff7 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
@@ -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