cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5993] Updating Jettison version to 1.3.6
Date Tue, 09 Sep 2014 09:21:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 065c4573a -> b4fd12c11


[CXF-5993] Updating Jettison version to 1.3.6


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b4fd12c1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b4fd12c1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b4fd12c1

Branch: refs/heads/2.7.x-fixes
Commit: b4fd12c11a7f6f4adcb49c6e8315d3f23e498e65
Parents: 065c457
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Sep 9 09:53:41 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Sep 9 10:21:27 2014 +0100

----------------------------------------------------------------------
 parent/pom.xml                                  |   2 +-
 .../cxf/jaxrs/provider/json/JSONProvider.java   |   8 +
 .../jaxrs/provider/json/JSONProviderTest.java   | 156 ++++++++++++++++++-
 .../jaxrs/provider/json/WadlGeneratorTest.java  |  10 +-
 4 files changed, 169 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b4fd12c1/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 15df59c..5db43ab 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -126,7 +126,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.5</cxf.jettison.version>
+        <cxf.jettison.version>1.3.6</cxf.jettison.version>
         <cxf.jetty.version>8.1.15.v20140411</cxf.jetty.version>
         <cxf.jetty.osgi.version>[7.6,8.2)</cxf.jetty.osgi.version>
         <cxf.jibx.version>1.2.5</cxf.jibx.version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/b4fd12c1/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
index 34bf30b..092f793 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
@@ -115,6 +115,7 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
     private TypeConverter typeConverter;
     private boolean attributesToElements;
     private boolean writeNullAsString = true;
+    private boolean escapeForwardSlashesAlways;
     
     @Override
     public void setAttributesToElements(boolean value) {
@@ -536,6 +537,10 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
             config.setIgnoreEmptyArrayValues(ignoreEmpty);
         }
         
+        if (escapeForwardSlashesAlways) {
+            config.setEscapeForwardSlashAlways(escapeForwardSlashesAlways);
+        }
+        
         
         boolean dropRootInJsonStream = dropRootNeeded && !dropElementsInXmlStreamProp;
         if (dropRootInJsonStream) {
@@ -642,4 +647,7 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
         this.ignoreEmptyArrayValues = ignoreEmptyArrayElements;
     }
 
+    public void setEscapeForwardSlashesAlways(boolean escape) {
+        this.escapeForwardSlashesAlways = escape;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b4fd12c1/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
index c5e1086..df9c734 100644
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
@@ -299,6 +299,25 @@ public class JSONProviderTest extends Assert {
         assertFalse(bos.toString().contains("\"id\":123"));
         assertTrue(bos.toString().startsWith("{\"Book\":"));
     }
+    @Test
+    public void testDoNotEscapeForwardSlashes() throws Exception {
+        JSONProvider<Book> provider = new JSONProvider<Book>();
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(new Book("http://cxf", 123), Book.class, Book.class,
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertTrue(bos.toString().contains("\"name\":\"http://cxf\""));
+    }
+    @Test
+    public void testEscapeForwardSlashesAlways() throws Exception {
+        JSONProvider<Book> provider = new JSONProvider<Book>();
+        provider.setEscapeForwardSlashesAlways(true);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(new Book("http://cxf", 123), Book.class, Book.class,
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertTrue(bos.toString().contains("\"name\":\"http:\\/\\/cxf\""));
+    }
     
     @Test
     public void testWriteNullValueAsString() throws Exception {
@@ -1007,6 +1026,85 @@ public class JSONProviderTest extends Assert {
     }
     
     @Test
+    public void testWriteArrayWithStructuredArrayKeyName() throws Exception {
+        JSONProvider<BeanA> p = new JSONProvider<BeanA>();
+        p.setSerializeAsArray(true);
+        p.setArrayKeys(Collections.singletonList("beana/beanb/name"));
+        BeanA beanA = new BeanA();
+        beanA.setName("beana");
+        BeanB beanB = new BeanB();
+        beanB.setName(Collections.singletonList("beanbArray"));
+        beanA.setBeanB(beanB);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(beanA, BeanA.class, BeanA.class, BeanA.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertTrue(s.contains("\"name\":[\"beanbArray\"]"));
+        assertTrue(s.contains("\"name\":\"beana\""));
+    }
+    @Test
+    public void testWriteArrayWithStructuredArrayKeyName2() throws Exception {
+        JSONProvider<BeanC> p = new JSONProvider<BeanC>();
+        p.setSerializeAsArray(true);
+        p.setDropRootElement(true);
+        List<String> keys = new LinkedList<String>();
+        keys.add("beanblist");
+        keys.add("beanblist/name");
+        p.setArrayKeys(keys);
+        BeanC beanC = new BeanC();
+        beanC.setName("beanc");
+        BeanB beanB = new BeanB();
+        beanB.setName(Collections.singletonList("beanbArray"));
+        beanC.setBeanBList(Collections.singletonList(beanB));
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(beanC, BeanC.class, BeanC.class, BeanC.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertTrue(s.contains("\"beanblist\":[{\"name\":[\"beanbArray\"]}]"));
+        assertTrue(s.contains("\"name\":\"beanc\""));
+    }
+    
+    @Test
+    public void testWriteArrayWithStructuredArrayKeyNameDropRoot() throws Exception {
+        JSONProvider<BeanA> p = new JSONProvider<BeanA>();
+        p.setSerializeAsArray(true);
+        p.setDropRootElement(true);
+        p.setArrayKeys(Collections.singletonList("beanb/name"));
+        BeanA beanA = new BeanA();
+        beanA.setName("beana");
+        BeanB beanB = new BeanB();
+        beanB.setName(Collections.singletonList("beanbArray"));
+        beanA.setBeanB(beanB);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(beanA, BeanA.class, BeanA.class, BeanA.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertTrue(s.contains("\"name\":[\"beanbArray\"]"));
+        assertTrue(s.contains("\"name\":\"beana\""));
+    }
+    @Test
+    public void testWriteArrayWithStructuredArrayKeyNameSingleBean() throws Exception {
+        JSONProvider<BeanB> p = new JSONProvider<BeanB>();
+        p.setSerializeAsArray(true);
+        p.setArrayKeys(Collections.singletonList("beanb/name"));
+        BeanB beanB = new BeanB();
+        beanB.setName(Collections.singletonList("beanbArray"));
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(beanB, BeanB.class, BeanB.class, BeanB.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertTrue(s.contains("\"name\":[\"beanbArray\"]"));
+    }
+    
+    @Test
     public void testWriteArrayAndNamespaceOnObject() throws Exception {
         JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
         p.setIgnoreNamespaces(true);
@@ -1786,5 +1884,61 @@ public class JSONProviderTest extends Assert {
         public void setId(String id) {
             this.id = id;
         }
-    }    
+    }
+    @XmlRootElement(name = "beana")
+    public static class BeanA {
+        private String name;
+        private BeanB beanB;
+        public BeanA() {
+            
+        }
+        public String getName() {
+            return name;
+        }
+        public void setName(String name) {
+            this.name = name;
+        }
+        public BeanB getBeanB() {
+            return beanB;
+        }
+        @XmlElement(name = "beanb")
+        public void setBeanB(BeanB beanB) {
+            this.beanB = beanB;
+        }
+    }
+    @XmlRootElement(name = "beanb")
+    public static class BeanB {
+        private List<String> name;
+        public BeanB() {
+            
+        }
+        public List<String> getName() {
+            return name;
+        }
+        public void setName(List<String> name) {
+            this.name = name;
+        }
+    }
+    @XmlRootElement(name = "beanc")
+    public static class BeanC {
+        private String name;
+        private List<BeanB> beanBList;
+        public BeanC() {
+            
+        }
+        public List<BeanB> getBeanBList() {
+            return beanBList;
+        }
+        @XmlElement(name = "beanblist")
+        public void setBeanBList(List<BeanB> beanBList) {
+            this.beanBList = beanBList;
+        }
+        public String getName() {
+            return name;
+        }
+        public void setName(String name) {
+            this.name = name;
+        }
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b4fd12c1/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/WadlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/WadlGeneratorTest.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/WadlGeneratorTest.java
index 973838b..66cc024 100644
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/WadlGeneratorTest.java
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/WadlGeneratorTest.java
@@ -89,13 +89,13 @@ public class WadlGeneratorTest extends Assert {
                   new MetadataMap<String, Object>(), os);
         String s = os.toString();
         String expected1 = 
-            "{\"application\":{\"grammars\":{\"include\":{\"@href\":\"http:\\/\\/localhost:8080\\/baz"
-            + "\\/json.schema\"}},\"resources\":{\"@base\":\"http:\\/\\/localhost:8080\\/baz\","
-            + "\"resource\":{\"@path\":\"\\/bookstore\\/{id}\"";
+            "{\"application\":{\"grammars\":{\"include\":{\"@href\":\"http://localhost:8080/baz"
+            + "/json.schema\"}},\"resources\":{\"@base\":\"http://localhost:8080/baz\","
+            + "\"resource\":{\"@path\":\"/bookstore/{id}\"";
         assertTrue(s.startsWith(expected1));
         String expected2 =
-            "\"response\":{\"representation\":[{\"@mediaType\":\"application\\/xml\"},"
-            + "{\"@element\":\"Chapter\",\"@mediaType\":\"application\\/json\"}]}";
+            "\"response\":{\"representation\":[{\"@mediaType\":\"application/xml\"},"
+            + "{\"@element\":\"Chapter\",\"@mediaType\":\"application/json\"}]}";
         assertTrue(s.contains(expected2));
     }
     


Mime
View raw message