cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1526450 - in /cxf/branches/2.6.x-fixes: ./ rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Date Thu, 26 Sep 2013 11:49:20 GMT
Author: sergeyb
Date: Thu Sep 26 11:49:19 2013
New Revision: 1526450

URL: http://svn.apache.org/r1526450
Log:
Merged revisions 1526448 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1526448 | sergeyb | 2013-09-26 12:42:03 +0100 (Thu, 26 Sep 2013) | 9 lines
  
  Merged revisions 1526445 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1526445 | sergeyb | 2013-09-26 12:32:24 +0100 (Thu, 26 Sep 2013) | 1 line
    
    [CXF-5301] Adding the name of the root to existing arrayKeys if root if array is needed
and the root is dropped in JSON
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1526448
  Merged /cxf/trunk:r1526445

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1526450&r1=1526449&r2=1526450&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Thu Sep 26 11:49:19 2013
@@ -32,9 +32,9 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -59,7 +59,6 @@ import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
 
-import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.MessageContext;
@@ -521,12 +520,20 @@ public class JSONProvider<T> extends Abs
         if (!writeNullAsString) {
             config.setWriteNullAsString(writeNullAsString);
         }
-        if (dropRootElement && !dropElementsInXmlStream) {
+        
+        boolean dropRootInJsonStream = dropRootElement && !dropElementsInXmlStream;
+        if (dropRootInJsonStream) {
             config.setDropRootElement(true);
         }
-        if (ignoreNamespaces && serializeAsArray && arrayKeys == null) {
-            arrayKeys = CastUtils.cast((List<?>)Collections.singletonList(qname.getLocalPart()));
+        if (ignoreNamespaces && serializeAsArray && (arrayKeys == null ||
dropRootInJsonStream)) {
+            if (arrayKeys == null) {
+                arrayKeys = new LinkedList<String>();
+            } else if (dropRootInJsonStream) {
+                arrayKeys = new LinkedList<String>(arrayKeys);
+            }
+            arrayKeys.add(qname.getLocalPart());
         }
+        
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
              writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
              isCollection || dropRootNeeded);

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java?rev=1526450&r1=1526449&r2=1526450&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Thu Sep 26 11:49:19 2013
@@ -29,6 +29,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -248,6 +249,30 @@ public class JSONProviderTest extends As
     }
     
     @Test
+    public void testWriteCollectionAsPureArray3() throws Exception {
+        
+        JSONProvider<ReportDefinition> provider 
+            = new JSONProvider<ReportDefinition>();
+        provider.setIgnoreNamespaces(true);
+        provider.setSerializeAsArray(true);
+        provider.setArrayKeys(Arrays.asList("parameterList".split(" ")));
+        provider.setDropRootElement(true);
+        provider.setDropElementsInXmlStream(false);
+        ReportDefinition r = new ReportDefinition();
+        r.setReportName("report");
+        ParameterDefinition paramDef = new ParameterDefinition("param");
+        r.addParameterDefinition(paramDef);
+        
+        Method m = ReportService.class.getMethod("findReport", new Class<?>[]{});
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(r, m.getReturnType(), m.getGenericReturnType(),
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertTrue(bos.toString().startsWith("[{\"parameterList\":["));
+        
+    }
+    
+    @Test
     public void testWriteBeanNoRootAtJsonLevel() throws Exception {
         JSONProvider<Book> provider = new JSONProvider<Book>();
         provider.setDropRootElement(true);



Mime
View raw message