cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r892988 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 21 Dec 2009 21:33:08 GMT
Author: dkulp
Date: Mon Dec 21 21:33:08 2009
New Revision: 892988

URL: http://svn.apache.org/viewvc?rev=892988&view=rev
Log:
[CXF-2422] Change the jaxrs DataBindingProvider to support generics

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java?rev=892988&r1=892987&r2=892988&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
Mon Dec 21 21:33:08 2009
@@ -40,7 +40,7 @@
 @Provider
 @Produces("application/json")
 @Consumes("application/json")
-public class DataBindingJSONProvider extends DataBindingProvider {
+public class DataBindingJSONProvider<T> extends DataBindingProvider<T> {
     
     private List<String> arrayKeys;
     private boolean serializeAsArray;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java?rev=892988&r1=892987&r2=892988&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
Mon Dec 21 21:33:08 2009
@@ -43,7 +43,7 @@
 @Provider
 @Produces({"application/xml", "application/*+xml", "text/xml" })
 @Consumes({"application/xml", "application/*+xml", "text/xml" })
-public class DataBindingProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object>
{
+public class DataBindingProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>
{
 
     private DataBinding binding;
     
@@ -62,13 +62,14 @@
         return true;
     }
 
-    public Object readFrom(Class<Object> clazz, Type genericType, Annotation[] annotations,
MediaType type, 
-                       MultivaluedMap<String, String> headers, InputStream is)
+    public T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, MediaType
type, 
+                      MultivaluedMap<String, String> headers, InputStream is)
         throws IOException {
         try {
             XMLStreamReader reader = createReader(clazz, genericType, is);
             DataReader<XMLStreamReader> dataReader = binding.createReader(XMLStreamReader.class);
-            return dataReader.read(null, reader, clazz);
+            Object o = dataReader.read(null, reader, clazz);
+            return o == null ? null : clazz.cast(o);
         } catch (Exception ex) {
             throw new WebApplicationException(ex);
         }
@@ -79,7 +80,7 @@
         return StaxUtils.createXMLStreamReader(is);
     }
     
-    public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
+    public long getSize(T t, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
         if (byte[].class.isAssignableFrom(t.getClass())) {
             return ((byte[])t).length;
         }
@@ -90,7 +91,7 @@
         return true;
     }
 
-    public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations,

+    public void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotations,

                         MediaType type, MultivaluedMap<String, Object> headers, OutputStream
os)
         throws IOException {
         try {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java?rev=892988&r1=892987&r2=892988&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
Mon Dec 21 21:33:08 2009
@@ -109,7 +109,7 @@
         Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
         DataBinding binding = new JAXBDataBinding();
         binding.initialize(s);
-        DataBindingJSONProvider p = new DataBindingJSONProvider();
+        DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
         p.setDataBinding(binding);
         Book b = new Book("CXF", 127L);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -142,7 +142,7 @@
         s.put("writeXsiType", true);
         AegisDatabinding binding = new AegisDatabinding();
         binding.initialize(s);
-        DataBindingJSONProvider p = new DataBindingJSONProvider();
+        DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
         p.setDataBinding(binding);
         Book b = new Book("CXF", 127L);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -158,7 +158,7 @@
         s.put("writeXsiType", true);
         AegisDatabinding binding = new AegisDatabinding();
         binding.initialize(s);
-        DataBindingJSONProvider p = new DataBindingJSONProvider();
+        DataBindingJSONProvider<List<Book>> p = new DataBindingJSONProvider<List<Book>>();
         p.setDataBinding(binding);
         
         Book b = new Book("CXF", 127L);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java?rev=892988&r1=892987&r2=892988&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
Mon Dec 21 21:33:08 2009
@@ -72,7 +72,7 @@
         s.put("writeXsiType", true);
         AegisDatabinding binding = new AegisDatabinding();
         binding.initialize(s);
-        DataBindingProvider p = new DataBindingProvider(binding);
+        DataBindingProvider<Book> p = new DataBindingProvider<Book>(binding);
         Book b = new Book("CXF", 127L);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         p.writeTo(b, Book.class, Book.class,
@@ -108,7 +108,7 @@
         Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
         DataBinding binding = new JAXBDataBinding();
         binding.initialize(s);
-        DataBindingProvider p = new DataBindingProvider(binding);
+        DataBindingProvider<Book> p = new DataBindingProvider<Book>(binding);
         Book b = new Book("CXF", 127L);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         p.writeTo(b, Book.class, Book.class,
@@ -117,18 +117,17 @@
         assertEquals(bos.toString(), data);
     }
     
-    @SuppressWarnings("unchecked")
     @Test
     public void testJAXBRead() throws Exception {
         String data = "<Book><id>127</id><name>CXF</name><state></state></Book>";
         Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
         DataBinding binding = new JAXBDataBinding();
         binding.initialize(s);
-        DataBindingProvider p = new DataBindingProvider(binding);
+        DataBindingProvider<Book> p = new DataBindingProvider<Book>(binding);
         ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
-        Book book = (Book)p.readFrom((Class)Book.class, Book.class,
-                                      new Annotation[0], MediaType.APPLICATION_XML_TYPE,

-                                      new MetadataMap<String, String>(), is);
+        Book book = p.readFrom(Book.class, Book.class,
+                               new Annotation[0], MediaType.APPLICATION_XML_TYPE, 
+                               new MetadataMap<String, String>(), is);
         assertEquals("CXF", book.getName());
         assertEquals(127L, book.getId());
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java?rev=892988&r1=892987&r2=892988&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
Mon Dec 21 21:33:08 2009
@@ -84,7 +84,7 @@
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         DataBinding db = new SDODataBinding();
         bean.setDataBinding(db);
-        DataBindingJSONProvider provider = new DataBindingJSONProvider();
+        DataBindingJSONProvider<Structure> provider = new DataBindingJSONProvider<Structure>();
         provider.setNamespaceMap(Collections.singletonMap("http://apache.org/structure/types",
"p0"));
         provider.setDataBinding(db);
         bean.setProvider(provider);



Mime
View raw message