cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494750 - in /cxf/branches/2.7.x-fixes: ./ rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Date Wed, 19 Jun 2013 19:43:11 GMT
Author: sergeyb
Date: Wed Jun 19 19:43:10 2013
New Revision: 1494750

URL: http://svn.apache.org/r1494750
Log:
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.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1494673

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

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

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1494750&r1=1494749&r2=1494750&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Wed Jun 19 19:43:10 2013
@@ -222,8 +222,8 @@ public class JSONProvider<T> extends Abs
             
             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.7.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java?rev=1494750&r1=1494749&r2=1494750&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Wed Jun 19 19:43:10 2013
@@ -194,6 +194,56 @@ 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<List<ReportDefinition>> provider 
+            = new JSONProvider<List<ReportDefinition>>();
+        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 = 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 testReadFromTags() throws Exception {
         MessageBodyReader<Tags> p = new JSONProvider<Tags>();
         byte[] bytes = 
@@ -1004,7 +1054,6 @@ public class JSONProviderTest extends As
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         provider.writeTo(many, ManyTags.class, ManyTags.class,
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        System.out.println(bos.toString());
     }
  
     @Test
@@ -1370,4 +1419,65 @@ public class JSONProviderTest extends As
         }
         
     }
+    
+    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