I have changed the code in SOAPContentElement that deals with the array part.
The original code says
if (obj != null)
{
Class objType = obj.getClass();
boolean isAssignable = JavaUtils.isAssignableFrom(javaType, objType);
if (isAssignable == false && javaType.isArray())
{
try
{
Method toArrayMethod = objType.getMethod("toArray", new Class[] {});
Class returnType = toArrayMethod.getReturnType();
if (JavaUtils.isAssignableFrom(javaType, returnType))
{
Method getValueMethod = objType.getMethod("getValue", new Class[]
{});
Object value = getValueMethod.invoke(obj, new Object[] {});
if (value != null)
{
// Do not invoke toArray if getValue returns null
obj = toArrayMethod.invoke(obj, new Object[] {});
}
else
{
// if the fragment did not indicate a null return
// by an xsi:nil we return an empty array
Class componentType = javaType.getComponentType();
obj = Array.newInstance(componentType, 0);
}
isAssignable = true;
}
}
catch (Exception e)
{
// ignore
}
}
I think it is better to look to the object that was deserialized to decide
wether this is an array. If it turns out to be an array then look for a setter
method that takes this array class as argument. If that exists set its value. I
think this way of unmarshalling fits better to the way the client artifacts are
generated by wstools. This is my version of the code
if (obj != null) {
Class objType = obj.getClass();
boolean isAssignable = JavaUtils.isAssignableFrom(javaType, objType);
if (isAssignable == false && objType.isArray()) { // Changed
try {
log.debug("Try to locate setValue method "+javaType);
Method setValueMethod = javaType.getMethod("setValue", new Class[]
{objType});
log.debug("Try to create new instance for "+javaType);
Object newInstance = javaType.newInstance();
log.debug("Try to invoke setValueMethod ");
setValueMethod.invoke(newInstance, new Object[] {obj});
isAssignable = true;
obj = newInstance;
} catch (Exception e) {
e.printStackTrace();
}
}
Erik
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983373#3983373
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983373
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user