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 08:56:59 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes b7dcd65f6 -> c4fb3c925


[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/c4fb3c92
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c4fb3c92
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c4fb3c92

Branch: refs/heads/3.0.x-fixes
Commit: c4fb3c9252c95ef6b93f02f5a4b27016073efb97
Parents: b7dcd65
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 09:56:35 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/c4fb3c92/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 3e4cfe2..2d39c90 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -122,7 +122,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/c4fb3c92/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 fcb6feb..d361fd1 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
@@ -116,6 +116,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) {
@@ -544,6 +545,10 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
             config.setIgnoreEmptyArrayValues(ignoreEmpty);
         }
         
+        if (escapeForwardSlashesAlways) {
+            config.setEscapeForwardSlashAlways(escapeForwardSlashesAlways);
+        }
+        
         
         boolean dropRootInJsonStream = dropRootNeeded && !dropElementsInXmlStreamProp;
         if (dropRootInJsonStream) {
@@ -677,4 +682,8 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
         }
         return null;
     }
+
+    public void setEscapeForwardSlashesAlways(boolean escape) {
+        this.escapeForwardSlashesAlways = escape;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c4fb3c92/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 adccbb5..040d90d 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
@@ -300,6 +300,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 {
@@ -1011,6 +1030,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);
@@ -1790,5 +1888,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/c4fb3c92/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 73be5ae..7d37f39 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
@@ -95,13 +95,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));
     }
     private Response handleRequest(WadlGenerator wg, Message m) {


Mime
View raw message