cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1170731 - in /cxf/trunk/rt/databinding/jaxb/src: main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
Date Wed, 14 Sep 2011 17:43:57 GMT
Author: dkulp
Date: Wed Sep 14 17:43:57 2011
New Revision: 1170731

URL: http://svn.apache.org/viewvc?rev=1170731&view=rev
Log:
[CXF-3611] Fix the detection of array/list types in
JAXBSchemaInitializer

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=1170731&r1=1170730&r2=1170731&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Wed Sep 14 17:43:57 2011
@@ -26,6 +26,7 @@ import java.lang.reflect.GenericArrayTyp
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.logging.Logger;
 
@@ -548,7 +549,10 @@ class JAXBSchemaInitializer extends Serv
         if (cls instanceof Class) {
             return ((Class)cls).isArray();
         } else if (cls instanceof ParameterizedType) {
-            return true;
+            ParameterizedType pt = (ParameterizedType)cls;
+            return pt.getActualTypeArguments().length == 1
+                && pt.getRawType() instanceof Class
+                && Collection.class.isAssignableFrom((Class)pt.getRawType());
         } else if (cls instanceof GenericArrayType) {
             return true;
         }

Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java?rev=1170731&r1=1170730&r2=1170731&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
Wed Sep 14 17:43:57 2011
@@ -26,6 +26,7 @@ import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.XMLConstants;
@@ -79,6 +80,9 @@ public class JAXBEncoderDecoderTest exte
     RequestWrapper wrapperAnnotation;
     JAXBContext context;
     Schema schema;
+    Map<String, String> mapField;
+    String arrayField[];
+    List<String> listField;
     
     @Before
     public void setUp() throws Exception {
@@ -100,6 +104,24 @@ public class JAXBEncoderDecoderTest exte
         assertNotNull(schema);
     }
 
+    
+    private Type getFieldType(String name) throws Exception {
+        return this.getClass()
+            .getDeclaredField(name)
+            .getGenericType();
+    }
+    
+    @Test
+    public void testCXF3611() throws Exception {
+        Map<String, String> foo = new HashMap<String, String>();
+        
+        assertTrue(JAXBSchemaInitializer.isArray(getFieldType("arrayField")));
+        assertTrue(JAXBSchemaInitializer.isArray(getFieldType("listField")));
+
+        assertFalse(JAXBSchemaInitializer.isArray(foo.getClass()));
+        assertFalse(JAXBSchemaInitializer.isArray(getFieldType("mapField")));
+    }
+    
     @Test
     public void testMarshallIntoDOM() throws Exception {
         String str = new String("Hello");



Mime
View raw message