cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1432312 - /cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Date Fri, 11 Jan 2013 22:14:51 GMT
Author: dkulp
Date: Fri Jan 11 22:14:50 2013
New Revision: 1432312

URL: http://svn.apache.org/viewvc?rev=1432312&view=rev
Log:
Merged revisions 1432236 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1432236 | dkulp | 2013-01-11 14:10:54 -0500 (Fri, 11 Jan 2013) | 2 lines

  [CXF-4745] Add a check in JAXB databinding to make sure the object to be written out actually
matches what JAXB is expecting it to be.

........

Modified:
    cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java

Modified: cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=1432312&r1=1432311&r2=1432312&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Fri Jan 11 22:14:50 2013
@@ -150,6 +150,7 @@ public class DataWriterImpl<T> extends J
         if (part != null && !part.isElement() && part.getTypeClass() != null)
{
             honorJaxbAnnotation = true;
         }
+        checkPart(part, obj);
         
         if (obj != null
             || !(part.getXmlSchema() instanceof XmlSchemaElement)) {
@@ -186,6 +187,43 @@ public class DataWriterImpl<T> extends J
         }
     }
 
+    private void checkPart(MessagePartInfo part, Object object) {
+        if (part == null || part.getTypeClass() == null || object == null) {
+            return;
+        }
+        Class<?> typeClass = part.getTypeClass();
+        if (typeClass == null) {
+            return;
+        }
+        if (typeClass.isPrimitive()) {
+            if (typeClass == Long.TYPE) {
+                typeClass = Long.class;
+            } else if (typeClass == Integer.TYPE) {
+                typeClass = Integer.class;
+            } else if (typeClass == Short.TYPE) {
+                typeClass = Short.class;
+            } else if (typeClass == Byte.TYPE) {
+                typeClass = Byte.class;
+            } else if (typeClass == Character.TYPE) {
+                typeClass = Character.class;
+            } else if (typeClass == Double.TYPE) {
+                typeClass = Double.class;
+            } else if (typeClass == Float.TYPE) {
+                typeClass = Float.class;
+            } else if (typeClass == Boolean.TYPE) {
+                typeClass = Boolean.class;
+            }
+        } else if (typeClass.isArray() && object instanceof Collection) {
+            //JAXB allows a pseudo [] <--> List equivalence
+            return;
+        }
+        if (!typeClass.isInstance(object)) {
+            throw new IllegalArgumentException("Part " + part.getName() + " should be of
type " 
+                + typeClass.getName() + ", not " 
+                + object.getClass().getName());
+        }
+    }
+
     private boolean needToRender(MessagePartInfo part) {
         if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
             XmlSchemaElement element = (XmlSchemaElement)part.getXmlSchema();



Mime
View raw message