-
Notifications
You must be signed in to change notification settings - Fork 119
Description
Line 80 in b7d1ff7
if(bi.jaxbType==Object.class && domHandler!=null) |
With a field defined like this:
@XmlAnyType(MyDomHandler.class)
private Object myField;
No matter what you assign to myField, MyDomHandler is never used to marshal, if the value assigned is not java.lang.Object. If you design MyDomHandler to extend DomHandler<String, StreamResult> and try to assign a string to myField, then this piece of JAXB won't call the handler:
JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
if(bi.jaxbType==Object.class && domHandler!=null)
// even if 'v' is a DOM node, it always derive from Object,
// so the getBeanInfo returns BeanInfo for Object
w.writeDom(v,domHandler,o,fieldName);
else
bi.serializeRoot(v,w);
because bi.jaxbType will not be Object.class, but String.class. This further fails with:
com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation.
Actually, it doesn't matter if the underlying field is of type Object, or String. The source code in SingleRefrenceNodeProperty always get java.lang.String as the jaxbType from JaxBeanInfo.
What's the purpose of allowing only pure java.lang.Objects to be handled by a custom handler? I can't see any possibility of passing any valuable information via such a basic type to the handler when marshalling. Thus, I can't see any real room for customization.