JAXB Marshalling Objects with java.lang.Object field

前端 未结 2 736
遥遥无期
遥遥无期 2020-12-15 00:37

I\'m trying to marshal an object that has an Object as one of its fields.

@XmlRootElement
public class TaskInstance implements Serializable {
   ...
   priva         


        
2条回答
  •  被撕碎了的回忆
    2020-12-15 01:13

    JAXB cannot marshal any old object, since it doesn't know how. For example, it wouldn't know what element name to use.

    If you need to handle this sort of wildcard, the only solution is to wrap the objects in a JAXBElement object, which contains enough information for JAXB to marshal to XML.

    Try something like:

    QName elementName = new QName(...); // supply element name here
    JAXBElement jaxbElement = new JAXBElement(elementName, mpd.getClass(), mpd);
    ti.setDataObject(jaxbElement);
    

提交回复
热议问题