summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 16:59:35 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 16:59:35 +0000
commit71b01b40ed17143ae45b85ec67b42e665f99cd29 (patch)
tree9f1c84369b526a0c2a302578ae5a66400e58953f /sca-java-2.x/trunk
parent815adf95622e0d2a31383e9dc7469108db03597f (diff)
Change json serialization to not marshal null values
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1053939 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java2
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java4
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JacksonHelper.java2
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java9
5 files changed, 15 insertions, 3 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 2882a31966..940ecccd8a 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
@@ -21,6 +21,7 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
org.codehaus.jackson,
org.codehaus.jackson.map,
+ org.codehaus.jackson.map.annotate,
org.codehaus.jackson.map.deser,
org.codehaus.jackson.map.introspect,
org.codehaus.jackson.map.ser,
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java
index a9edc66ae8..5cf48645b8 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java
@@ -41,7 +41,7 @@ public class JSON2JavaBean implements PullTransformer<Object, Object> {
throw new TransformationException(e);
}
serializer.setMarshallClassHints(true);
- serializer.setMarshallNullAttributes(true);
+ serializer.setMarshallNullAttributes(false);
}
public Object transform(Object source, TransformationContext context) {
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java
index 17ed06298e..0c0683b16c 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java
@@ -19,10 +19,10 @@
package org.apache.tuscany.sca.databinding.json;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
import org.apache.tuscany.sca.databinding.TransformationException;
-import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;
import org.jabsorb.JSONSerializer;
import org.jabsorb.serializer.SerializerState;
@@ -38,7 +38,7 @@ public class JavaBean2JSON extends BaseTransformer<Object, Object> implements Pu
throw new TransformationException(e);
}
serializer.setMarshallClassHints(true);
- serializer.setMarshallNullAttributes(true);
+ serializer.setMarshallNullAttributes(false);
}
@Override
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 00ddc2601d..459462fa97 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
@@ -38,6 +38,7 @@ import org.codehaus.jackson.map.AnnotationIntrospector;
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.StdDeserializerProvider;
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
@@ -100,6 +101,7 @@ public class JacksonHelper {
// [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);
return mapper;
}
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java b/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java
index 3b36f5be74..9ec9f21d7e 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java
@@ -42,6 +42,7 @@ public class JavaBean2JSONTestCase {
private String friends[];
private List<String> books;
private YourBean you;
+ private String note;
public String getName() {
return name;
@@ -91,6 +92,14 @@ public class JavaBean2JSONTestCase {
this.you = you;
}
+ public String getNote() {
+ return note;
+ }
+
+ public void setNote(String note) {
+ this.note = note;
+ }
+
}
public static class YourBean {