cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1349717 - in /cxf/trunk/rt/rs/extensions/providers/src: main/java/org/apache/cxf/jaxrs/provider/json/ test/java/org/apache/cxf/jaxrs/provider/json/ test/java/org/apache/cxf/jaxrs/resources/jaxb/
Date Wed, 13 Jun 2012 10:05:39 GMT
Author: sergeyb
Date: Wed Jun 13 10:05:39 2012
New Revision: 1349717

URL: http://svn.apache.org/viewvc?rev=1349717&view=rev
Log:
[CXF-4374] The actual updates to JSONProvider

Modified:
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
    cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java

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=1349717&r1=1349716&r2=1349717&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
Wed Jun 13 10:05:39 2012
@@ -302,7 +302,7 @@ public class JSONProvider<T> extends Abs
             name = wrapperMap.get(cls.getName());
         }
         if (name == null) {
-            QName qname = getQName(cls, type, null, false);
+            QName qname = getQName(cls, type, null);
             if (qname != null) {
                 name = qname.getLocalPart();
                 String prefix = qname.getPrefix();
@@ -475,7 +475,7 @@ public class JSONProvider<T> extends Abs
     protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass,

         Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         
-        QName qname = getQName(actualClass, genericType, actualObject, true);
+        QName qname = getQName(actualClass, genericType, actualObject);
         if (ignoreNamespaces && (isCollection  || dropRootElement)) {        
             qname = new QName(qname.getLocalPart());
         }
@@ -512,27 +512,19 @@ public class JSONProvider<T> extends Abs
         marshal(ms, actualObject, actualClass, genericType, enc, os, false);
     }
     
-    private QName getQName(Class<?> cls, Type type, Object object, boolean allocatePrefix)

+    private QName getQName(Class<?> cls, Type type, Object object) 
         throws Exception {
         QName qname = getJaxbQName(cls, type, object, false);
         if (qname != null) {
-            String prefix = getPrefix(qname.getNamespaceURI(), allocatePrefix);
+            String prefix = getPrefix(qname.getNamespaceURI());
             return new QName(qname.getNamespaceURI(), qname.getLocalPart(), prefix);
         }
         return null;
     }
     
-    private String getPrefix(String namespace, boolean allocatePrefix) {
+    private String getPrefix(String namespace) {
         String prefix = namespaceMap.get(namespace);
-        if (prefix == null) {
-            if (allocatePrefix && namespace.length() > 0) {
-                prefix = "ns" + (namespaceMap.size() + 1);
-                namespaceMap.put(namespace, prefix);
-            } else {
-                prefix = "";
-            }
-        }
-        return prefix;
+        return prefix == null ? "" : prefix;
     }
     
     public void setWriteXsiType(boolean writeXsiType) {

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=1349717&r1=1349716&r2=1349717&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
Wed Jun 13 10:05:39 2012
@@ -590,6 +590,7 @@ public class JSONProviderTest extends As
     @Test
     public void testWriteToSingleQualifiedTag2() throws Exception {
         JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
+        p.setNamespaceMap(Collections.singletonMap("http://tags", "ns1"));
         TagVO2 tag = createTag2("a", "b");
         
         ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -598,7 +599,6 @@ public class JSONProviderTest extends As
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
         
         String s = os.toString();
-        
         assertEquals("{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
         
     }
@@ -997,6 +997,20 @@ public class JSONProviderTest extends As
     
     
     @Test
+    public void testWriteWithXmlRootElementAndPackageInfo() throws Exception {
+        JSONProvider<org.apache.cxf.jaxrs.resources.jaxb.Book2> provider = 
+            new JSONProvider<org.apache.cxf.jaxrs.resources.jaxb.Book2>();
+        org.apache.cxf.jaxrs.resources.jaxb.Book2 book = 
+            new org.apache.cxf.jaxrs.resources.jaxb.Book2(333);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(book, org.apache.cxf.jaxrs.resources.jaxb.Book2.class, 
+                         org.apache.cxf.jaxrs.resources.jaxb.Book2.class,
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertEquals("{\"os.thebook2\":{\"id\":333}}", bos.toString());
+    }
+    
+    @Test
     public void testDropQualifiedElements() throws Exception {
         JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
         List<String> list = new ArrayList<String>();
@@ -1051,7 +1065,7 @@ public class JSONProviderTest extends As
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         provider.writeTo(tag, TagVO2.class, TagVO2.class,
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        String expected = "{\"ns1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        String expected = "{\"ns2.t\":{\"ns2.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
         assertEquals(expected, bos.toString());
     }
     
@@ -1065,7 +1079,7 @@ public class JSONProviderTest extends As
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         provider.writeTo(tag, TagVO2.class, TagVO2.class,
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        String expected = "{\"ps1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        String expected = "{\"ps1.t\":{\"ns2.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
         assertEquals(expected, bos.toString());
     }
     

Modified: cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java?rev=1349717&r1=1349716&r2=1349717&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
Wed Jun 13 10:05:39 2012
@@ -16,6 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://superbooks")
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://superbooks",
+ xmlns = { @XmlNs(prefix = "os", namespaceURI = "http://superbooks") })
 package org.apache.cxf.jaxrs.resources.jaxb;
 
+import javax.xml.bind.annotation.XmlNs;
+



Mime
View raw message