Skip to content

Custom DomHandler from @XmlAnyType is not called #1829

@pablo53

Description

@pablo53

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions