cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1551499 - in /cxf/trunk: parent/ rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/ rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/ rt/rs/extensions/providers/src/test/java/org/a...
Date Tue, 17 Dec 2013 10:23:07 GMT
Author: sergeyb
Date: Tue Dec 17 10:23:07 2013
New Revision: 1551499

URL: http://svn.apache.org/r1551499
Log:
[CXF-5463] Update Jettion version to 1.3.5

Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
    cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=1551499&r1=1551498&r2=1551499&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Tue Dec 17 10:23:07 2013
@@ -114,7 +114,7 @@
         <cxf.jaxb.xjc.version>${cxf.jaxb21.xjc.version}</cxf.jaxb.xjc.version>
         <cxf.joda.time.version>2.2</cxf.joda.time.version>
         <cxf.jdom.version>1.0</cxf.jdom.version>
-        <cxf.jettison.version>1.3.4</cxf.jettison.version>
+        <cxf.jettison.version>1.3.5</cxf.jettison.version>
         <cxf.jetty.version>8.1.14.v20131031</cxf.jetty.version>
         <cxf.jetty.osgi.version>[7.6,8.2)</cxf.jetty.osgi.version>
         <cxf.jibx.version>1.2.5</cxf.jibx.version>

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1551499&r1=1551498&r2=1551499&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Tue Dec 17 10:23:07 2013
@@ -102,7 +102,8 @@ public class JSONProvider<T> extends Abs
     private boolean dropRootElement;
     private boolean dropElementsInXmlStream = true;
     private boolean dropCollectionWrapperElement;
-    private boolean ignoreMixedContent; 
+    private boolean ignoreMixedContent;
+    private boolean ignoreEmptyArrayValues;
     private boolean writeXsiType = true;
     private boolean readXsiType = true;
     private boolean ignoreNamespaces;
@@ -110,7 +111,6 @@ public class JSONProvider<T> extends Abs
     private TypeConverter typeConverter;
     private boolean attributesToElements;
     private boolean writeNullAsString = true;
-    private boolean readNullAsEmptyString = true;
     
     @Override
     public void setAttributesToElements(boolean value) {
@@ -283,7 +283,6 @@ public class JSONProvider<T> extends Abs
                                                   readXsiType, 
                                                   namespaceMap, 
                                                   primitiveArrayKeys,
-                                                  readNullAsEmptyString,
                                                   getDepthProperties());
         }
         reader = createTransformReaderIfNeeded(reader, is);
@@ -525,6 +524,10 @@ public class JSONProvider<T> extends Abs
         if (!writeNullAsString) {
             config.setWriteNullAsString(writeNullAsString);
         }
+        if (ignoreEmptyArrayValues) {
+            config.setIgnoreEmptyArrayValues(ignoreEmptyArrayValues);
+        }
+        
         
         boolean dropRootInJsonStream = dropRootElement && !dropElementsInXmlStream;
         if (dropRootInJsonStream) {
@@ -609,8 +612,8 @@ public class JSONProvider<T> extends Abs
         this.writeNullAsString = writeNullAsString;
     }
 
-    public void setReadNullAsEmptyString(boolean readNullAsString) {
-        this.readNullAsEmptyString = readNullAsString;
+    public void setIgnoreEmptyArrayValues(boolean ignoreEmptyArrayElements) {
+        this.ignoreEmptyArrayValues = ignoreEmptyArrayElements;
     }
 
 }

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java?rev=1551499&r1=1551498&r2=1551499&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
Tue Dec 17 10:23:07 2013
@@ -136,13 +136,12 @@ public final class JSONUtils {
     
     public static XMLStreamReader createStreamReader(InputStream is, boolean readXsiType,
         ConcurrentHashMap<String, String> namespaceMap) throws Exception {
-        return createStreamReader(is, readXsiType, namespaceMap, null, true, null);
+        return createStreamReader(is, readXsiType, namespaceMap, null, null);
     }
     
     public static XMLStreamReader createStreamReader(InputStream is, boolean readXsiType,
         ConcurrentHashMap<String, String> namespaceMap,
         List<String> primitiveArrayKeys,
-        boolean readNullAsString,
         DocumentDepthProperties depthProps) throws Exception {
         if (readXsiType) {
             namespaceMap.putIfAbsent(XSI_URI, XSI_PREFIX);
@@ -152,9 +151,7 @@ public final class JSONUtils {
             conf.setPrimitiveArrayKeys(
                 new HashSet<String>(primitiveArrayKeys));
         }
-        if (!readNullAsString) {
-            conf.setReadNullAsEmptyString(readNullAsString);
-        }
+        
         XMLInputFactory factory = depthProps != null 
             ? new JettisonMappedReaderFactory(conf, depthProps) 
             : new MappedXMLInputFactory(conf);

Modified: cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java?rev=1551499&r1=1551498&r2=1551499&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Tue Dec 17 10:23:07 2013
@@ -1028,6 +1028,32 @@ public class JSONProviderTest extends As
             "{\"ManyTags\":{\"tags\":{\"list\":[{\"group\":\"b\",\"name\":\"a\"}]}}}",
             s);
     }
+    
+    @Test
+    public void testManyTagsEmptyArray() throws Exception {
+        JSONProvider<ManyTags> p = new JSONProvider<ManyTags>() {
+            protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass,

+                Type genericType, String enc, OutputStream os, boolean isCollection) throws
Exception {
+                return new EmptyListWriter(
+                    super.createWriter(actualObject, actualClass, genericType, enc, os, isCollection));
+            }
+        };
+        p.setSerializeAsArray(true);
+        p.setArrayKeys(Collections.singletonList("list"));
+        p.setIgnoreEmptyArrayValues(true);
+        Tags tags = new Tags();
+        tags.addTag(createTag("a", "b"));
+        ManyTags many = new ManyTags();
+        many.setTags(tags);
+        
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(many, ManyTags.class, ManyTags.class, ManyTags.class.getAnnotations(),

+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertEquals("{\"ManyTags\":{\"tags\":{\"list\":[]}}}", s);
+    }
 
     @Test
     public void testInDropElement() throws Exception {
@@ -1648,6 +1674,32 @@ public class JSONProviderTest extends As
         }
     }
     
+    private static class EmptyListWriter extends DelegatingXMLStreamWriter {
+        private int count;
+        public EmptyListWriter(XMLStreamWriter writer) {
+            super(writer);
+        }
+
+        public void writeCharacters(String text) throws XMLStreamException {
+        }
+        
+        public void writeStartElement(String p, String local, String uri) throws XMLStreamException
{
+            if ("group".equals(local) || "name".equals(local)) {
+                count++; 
+            } else {
+                super.writeStartElement(p, local, uri);
+            }
+        }
+        
+        public void writeEndElement() throws XMLStreamException {
+            if (count == 0) {
+                super.writeEndElement(); 
+            } else {
+                count--;
+            }
+        }
+    }
+    
     private static class NullWriter extends DelegatingXMLStreamWriter {
         public NullWriter(XMLStreamWriter writer) {
             super(writer);



Mime
View raw message