cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1038746 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Date Wed, 24 Nov 2010 18:20:21 GMT
Author: sergeyb
Date: Wed Nov 24 18:20:20 2010
New Revision: 1038746

URL: http://svn.apache.org/viewvc?rev=1038746&view=rev
Log:
[CXF-3148] Improving the code dealing with explicit collections by applying a fix on behalf
of Dobes Vandermeer

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1038746&r1=1038745&r2=1038746&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Wed Nov 24 18:20:20 2010
@@ -27,6 +27,7 @@ import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -256,11 +257,16 @@ public class JAXBElementProvider extends
                                      Type genericType, String encoding, OutputStream os,
MediaType m) 
         throws Exception {
         
-        Object[] arr = originalCls.isArray() ? (Object[])actualObject : ((Collection)actualObject).toArray();
+        Collection c = originalCls.isArray() ? Arrays.asList((Object[]) actualObject) 
+                                             : (Collection) actualObject;
+
+        Iterator it = c.iterator();
         
+        Object firstObj = it.hasNext() ? it.next() : null;
+
         QName qname = null;
-        if (arr.length > 0 && arr[0] instanceof JAXBElement) {
-            JAXBElement el = (JAXBElement)arr[0];
+        if (firstObj instanceof JAXBElement) {
+            JAXBElement el = (JAXBElement)firstObj;
             qname = el.getName();
             actualClass = el.getDeclaredType();
         } else {
@@ -284,9 +290,15 @@ public class JAXBElementProvider extends
             endTag = "</" + qname.getLocalPart() + ">";
         }
         os.write(startTag.getBytes());
-        for (Object o : arr) {
-            marshalCollectionMember(o instanceof JAXBElement ? ((JAXBElement)o).getValue()
: o, 
-                                    actualClass, genericType, encoding, os, m, qname.getNamespaceURI());
   
+        if (firstObj != null) {
+            marshalCollectionMember(firstObj instanceof JAXBElement 
+                ? ((JAXBElement) firstObj).getValue() : firstObj, actualClass, genericType,
encoding, os, m, 
+                qname.getNamespaceURI());
+            while (it.hasNext()) {
+                Object o = it.next();
+                marshalCollectionMember(o instanceof JAXBElement ? ((JAXBElement)o).getValue()
: o, 
+                                    actualClass, genericType, encoding, os, m, qname.getNamespaceURI());
+            }
         }
         os.write(endTag.getBytes());
     }



Mime
View raw message