cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1233289 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Date Thu, 19 Jan 2012 11:29:14 GMT
Author: sergeyb
Date: Thu Jan 19 11:29:14 2012
New Revision: 1233289

URL: http://svn.apache.org/viewvc?rev=1233289&view=rev
Log:
[CXF-4043] Some updates to do with ignoreNamespaces & collections

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1233289&r1=1233288&r2=1233289&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Thu Jan 19 11:29:14 2012
@@ -467,7 +467,9 @@ public class JSONProvider<T> extends Abs
         Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         
         QName qname = getQName(actualClass, genericType, actualObject, true);
-        
+        if (ignoreNamespaces && isCollection) {        
+            qname = new QName(qname.getLocalPart());
+        }
         if (BADGER_FISH_CONVENTION.equals(convention)) {
             return JSONUtils.createBadgerFishWriter(os);
         }
@@ -482,7 +484,7 @@ public class JSONProvider<T> extends Abs
              writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
              isCollection || dropRootElement);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
-        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces &&
!isCollection);
+        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
         return createTransformWriterIfNeeded(writer, os);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java?rev=1233289&r1=1233288&r2=1233289&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
Thu Jan 19 11:29:14 2012
@@ -221,6 +221,11 @@ public final class JSONUtils {
         }
         
         @Override
+        public void writeStartElement(String local) throws XMLStreamException {
+            this.writeStartElement("", local, "");
+        }
+        
+        @Override
         public void writeEndElement() throws XMLStreamException {
             index--;
             if (rootDropped && index == 0) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=1233289&r1=1233288&r2=1233289&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Thu Jan 19 11:29:14 2012
@@ -268,6 +268,22 @@ public class JSONProviderTest extends As
     }
     
     @Test
+    public void testWriteToSingleTag2NoNs() throws Exception {
+        JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
+        p.setIgnoreNamespaces(true);
+        TagVO2 tag = createTag2("a", "b");
+        
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(tag, TagVO2.class, TagVO2.class, TagVO2.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertEquals("{\"thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
+        
+    }
+    
+    @Test
     public void testCopyReaderToDocument() throws Exception {
         String s = "{\"tagVO\":{\"group\":\"b\",\"name\":\"a\"}}";
         
@@ -451,7 +467,6 @@ 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());
         
@@ -563,6 +578,7 @@ public class JSONProviderTest extends As
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
         
         String s = os.toString();
+        System.out.println(s);
         assertEquals("{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
         
     }



Mime
View raw message