You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/01/19 00:25:36 UTC

svn commit: r1233114 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java

Author: sergeyb
Date: Wed Jan 18 23:25:35 2012
New Revision: 1233114

URL: http://svn.apache.org/viewvc?rev=1233114&view=rev
Log:
Merged revisions 1233113 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

................
  r1233113 | sergeyb | 2012-01-18 23:23:35 +0000 (Wed, 18 Jan 2012) | 9 lines
  
  Merged revisions 1233112 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1233112 | sergeyb | 2012-01-18 23:21:25 +0000 (Wed, 18 Jan 2012) | 1 line
    
    [CXF-4043] Minor update to JSONProvider to properly deal with a custom prefix
  ........
................

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 18 23:25:35 2012
@@ -1,2 +1,2 @@
-/cxf/branches/2.5.x-fixes:1233076
-/cxf/trunk:1233075
+/cxf/branches/2.5.x-fixes:1233076,1233113
+/cxf/trunk:1233075,1233112

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1233114&r1=1233113&r2=1233114&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java Wed Jan 18 23:25:35 2012
@@ -390,11 +390,18 @@ public class JSONProvider extends Abstra
             } else {
                 qname = getCollectionWrapperQName(actualClass, genericType, firstObj, false);
             }
-            if (qname.getNamespaceURI().length() > 0) {
-                startTag = "{\"ns1." + qname.getLocalPart() + "\":[";
-            } else {
-                startTag = "{\"" + qname.getLocalPart() + "\":[";
+            String prefix = "";
+            if (!ignoreNamespaces) {
+                if (namespaceMap.containsKey(qname.getNamespaceURI())) {
+                    prefix = namespaceMap.get(qname.getNamespaceURI());
+                    if (!prefix.isEmpty()) {
+                        prefix += ".";
+                    }
+                } else if (qname.getNamespaceURI().length() > 0) {
+                    prefix = "ns1.";
+                }
             }
+            startTag = "{\"" + prefix + qname.getLocalPart() + "\":[";
             endTag = "]}";
         } else if (serializeAsArray) {
             startTag = "[";
@@ -475,7 +482,7 @@ public class JSONProvider extends Abstra
              writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
              isCollection || dropRootElement);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
-        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces && !isCollection);
         return createTransformWriterIfNeeded(writer, os);
     }
     

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=1233114&r1=1233113&r2=1233114&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java Wed Jan 18 23:25:35 2012
@@ -400,24 +400,32 @@ public class JSONProviderTest extends As
     public void testWriteQualifiedCollection() throws Exception {
         String data = "{\"ns1.tag\":[{\"group\":\"b\",\"name\":\"a\"}"
             + ",{\"group\":\"d\",\"name\":\"c\"}]}";
-        doWriteQualifiedCollection(false, false, data);
+        doWriteQualifiedCollection(false, false, false, data);
+    }
+    
+    @Test
+    public void testWriteQualifiedCollectionDropNs() throws Exception {
+        String data = "{\"tag\":[{\"group\":\"b\",\"name\":\"a\"}"
+            + ",{\"group\":\"d\",\"name\":\"c\"}]}";
+        doWriteQualifiedCollection(false, false, true, data);
     }
     
     @Test
     public void testWriteQualifiedCollection2() throws Exception {
         String data = "{{\"group\":\"b\",\"name\":\"a\"}"
             + ",{\"group\":\"d\",\"name\":\"c\"}}";
-        doWriteQualifiedCollection(true, false, data);
+        doWriteQualifiedCollection(true, false, false, data);
     }
     
     @Test
     public void testWriteQualifiedCollection3() throws Exception {
         String data = "[{\"group\":\"b\",\"name\":\"a\"}"
             + ",{\"group\":\"d\",\"name\":\"c\"}]";
-        doWriteQualifiedCollection(true, true, data);
+        doWriteQualifiedCollection(true, true, false, data);
     }
     
-    public void doWriteQualifiedCollection(boolean drop, boolean serializeAsArray, String data) 
+    public void doWriteQualifiedCollection(boolean drop, boolean serializeAsArray, 
+                                           boolean ignoreNamespaces, String data) 
         throws Exception {
         JSONProvider p = new JSONProvider();
         p.setCollectionWrapperName("{http://tags}tag");
@@ -426,6 +434,8 @@ public class JSONProviderTest extends As
         Map<String, String> namespaceMap = new HashMap<String, String>();
         namespaceMap.put("http://tags", "ns1");
         p.setNamespaceMap(namespaceMap);
+        p.setIgnoreNamespaces(ignoreNamespaces);
+        
         List<TagVO2> tags = new ArrayList<TagVO2>();
         tags.add(createTag2("a", "b"));
         tags.add(createTag2("c", "d"));
@@ -447,6 +457,7 @@ public class JSONProviderTest extends As
         Method m = CollectionsResource.class.getMethod("getBooks", new Class[0]);
         p.writeTo(books, m.getReturnType(), m.getGenericReturnType(), new Annotation[0], 
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
+        System.out.println(os.toString());
         assertEquals("{\"Book\":[{\"id\":123,\"name\":\"CXF\",\"state\":\"\"}]}",
                      os.toString());