Announcement Announcement Module
Collapse
No announcement yet.
MarshallingHttpMessageConverter does not extract value from JaxbElement, why? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MarshallingHttpMessageConverter does not extract value from JaxbElement, why?

    Hi all,

    Spring's MarshallingHttpMessageConverter readFromSource-method does only check if the unmarshalled object is of the given type clazz.
    With JAXB it is possible that the unmarshalled object is of type JaxbElement (e.g. when the schema contains substitution groups), that contains an object that is of type clazz.

    So I had to extend the class and do the following:
    Code:
    ...
    
    if (JAXBElement.class.isAssignableFrom(result.getClass())) {
    	result = ((JAXBElement<?>) result).getValue();
    }
    if (!clazz.isInstance(result)) {
    	throw new TypeMismatchException(result, clazz);
    }
    return result;
    
    ...
    So my question is why does Spring not do what I did in my extension? Might that be an improvement?

    Best regards,
    Florian
Working...
X