Author: dkulp
Date: Fri Jan 11 19:10:54 2013
New Revision: 1432236
URL: http://svn.apache.org/viewvc?rev=1432236&view=rev
Log:
[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/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=1432236&r1=1432235&r2=1432236&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
(original)
+++
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Fri Jan 11 19:10:54 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();