cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494766 - in /cxf/branches/2.5.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
Date Wed, 19 Jun 2013 20:35:40 GMT
Author: sergeyb
Date: Wed Jun 19 20:35:39 2013
New Revision: 1494766

URL: http://svn.apache.org/r1494766
Log:
Merged revisions 1494757 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1494757 | sergeyb | 2013-06-19 20:52:22 +0100 (Wed, 19 Jun 2013) | 16 lines
  
  Merged revisions 1494750 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
  
  ................
    r1494750 | sergeyb | 2013-06-19 20:43:10 +0100 (Wed, 19 Jun 2013) | 9 lines
    
    Merged revisions 1494673 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1494673 | sergeyb | 2013-06-19 17:03:39 +0100 (Wed, 19 Jun 2013) | 1 line
      
      [CXF-5086] Minor fix to JSONProvider to get collections read if JAXBElement is involved
    ........
  ................
................

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

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1494750
  Merged /cxf/trunk:r1494673
  Merged /cxf/branches/2.6.x-fixes:r1494757

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

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1494766&r1=1494765&r2=1494766&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Wed Jun 19 20:35:39 2013
@@ -227,8 +227,8 @@ public class JSONProvider extends Abstra
             
             Object response = null;
             if (JAXBElement.class.isAssignableFrom(type) 
-                || unmarshalAsJaxbElement
-                || jaxbElementClassMap != null && jaxbElementClassMap.containsKey(theType.getName()))
{
+                || !isCollection && (unmarshalAsJaxbElement 
+                || jaxbElementClassMap != null && jaxbElementClassMap.containsKey(theType.getName())))
{
                 response = unmarshaller.unmarshal(xsr, theType);
             } else {
                 response = unmarshaller.unmarshal(xsr);

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=1494766&r1=1494765&r2=1494766&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Wed Jun 19 20:35:39 2013
@@ -593,6 +593,53 @@ public class JSONProviderTest extends As
     }
     
     @Test
+    public void testWriteCollectionParameterDef() 
+        throws Exception {
+        doTestWriteCollectionParameterDef(false);
+    }
+    
+    @Test
+    public void testWriteCollectionParameterDefAsJaxbElement() 
+        throws Exception {
+        doTestWriteCollectionParameterDef(true);
+    }
+
+    private void doTestWriteCollectionParameterDef(boolean asJaxbElement) 
+        throws Exception {
+        JSONProvider provider = new JSONProvider();
+        provider.setMarshallAsJaxbElement(asJaxbElement);
+        provider.setUnmarshallAsJaxbElement(asJaxbElement);
+        ReportDefinition r = new ReportDefinition();
+        r.setReportName("report");
+        r.addParameterDefinition(new ParameterDefinition("param"));
+        List<ReportDefinition> reports = Collections.singletonList(r);
+        
+        Method m = ReportService.class.getMethod("findAllReports", new Class<?>[]{});
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(reports, m.getReturnType(), m.getGenericReturnType(),
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        @SuppressWarnings({
+            "unchecked", "rawtypes"
+        })
+        List<ReportDefinition> reports2 = (List<ReportDefinition>)provider.readFrom((Class)m.getReturnType(),
+                          m.getGenericReturnType(),
+                          new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                          new MetadataMap<String, String>(), new ByteArrayInputStream(bos.toString().getBytes()));
+        assertNotNull(reports2);
+        assertEquals(1, reports2.size());
+        ReportDefinition rd = reports2.get(0);
+        assertEquals("report", rd.getReportName());
+        
+        List<ParameterDefinition> params = rd.getParameterList();
+        assertNotNull(params);
+        assertEquals(1, params.size());
+        ParameterDefinition pd = params.get(0);
+        assertEquals("param", pd.getName());
+        
+    } 
+
+    @Test
     public void testWriteToSingleQualifiedTag2() throws Exception {
         JSONProvider p = new JSONProvider();
         TagVO2 tag = createTag2("a", "b");
@@ -1315,4 +1362,65 @@ public class JSONProviderTest extends As
             return books;
         }
     }
+
+    interface ReportService {
+
+        List<ReportDefinition> findAllReports();
+
+    } 
+    
+    public static class ParameterDefinition {
+        private String name;
+        public ParameterDefinition() {
+        }
+        public ParameterDefinition(String name) {
+            this.name = name;
+        }
+        public String getName() {
+            return name;
+        }
+    
+        public void setName(String name) {
+            this.name = name;
+        }
+        
+    }
+
+    @XmlRootElement
+    public static class ReportDefinition {
+        private String reportName;
+       
+        private List<ParameterDefinition> parameterList;
+       
+        public ReportDefinition() {
+       
+        }
+       
+        public ReportDefinition(String reportName) {
+            this.reportName = reportName;
+        }
+       
+        public String getReportName() {
+            return reportName;
+        }
+
+        public void setReportName(String reportName) {
+            this.reportName = reportName;
+        }
+       
+        public List<ParameterDefinition> getParameterList() {
+            return parameterList;
+        }
+
+        public void setParameterList(List<ParameterDefinition> parameterList) {
+            this.parameterList = parameterList;
+        }
+       
+        public void addParameterDefinition(ParameterDefinition parameterDefinition) {
+            if (parameterList == null) {
+                parameterList = new ArrayList<ParameterDefinition>();
+            }
+            parameterList.add(parameterDefinition);
+        }
+    }
 }



Mime
View raw message