Details
-
Type: New Feature
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.4
-
Component/s: None
-
Labels:None
Description
The implicit unmarshalling support should be expanded beyond collections to include java array types. The use of array binding has the advantage infering the type of the element when it is not provided by the type attribute in the message. It's a common binding for XSD based services.
This is not an easy case to extend because it involves overriding of ReflectionConverer, which has a lot of additional responsiblities. However, I was able to make it work with relatively easy changes. I've included changes I made to ReflectionConverter below as snippets.
....
private class ArrayElem {
public List list;
public Class type;
ArrayElem(List list, Class type)
}
...
Map implciitArrays = null;
// ... add as additional condition before fieldClass.isAssiableFrom(...) ....
if (fieldClass.isArray()) {
Class elementClass = fieldClass.getComponentType();
// optional type may be present for polymorphic types:
String typeName = reader.getAttribute(mapper.attributeForImplementationClass());
if (typeName != null)
Object value = context.convertAnother(result, elementClass);
if (implciitArrays == null) implciitArrays = new HashMap(); // lazy instantiation
ArrayElem elem = (ArrayElem) implciitArrays.get(fieldName);
if (elem == null)
elem.list.add(value);
} else....
///.... At end of unmarshall method....
// write implict arrays after all values are read
if (implciitArrays != null) {
for (Iterator iter = implciitArrays.entrySet().iterator(); iter.hasNext()
}
This issue was reported over a year ago and a workaround seems to be provided. However no comment or response so far.
I think implicit arrays are a quite common use case. Is there any valid reason why this has not yet been implemented?
Regards,
Johan