JAXB是否提供了一种检查对象/XML是否为编组/不明确的方法



我有一些代码,可以将对象推向XML字符串,以通过JMS发送。但是,在我实际调用此代码之前,我想指出该通话是否会成功。像

JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
Marshaller m = ctx.createMarshaller();
if(m.canMarshal(o)) {
    return m.marshal(o);
} else {
    throw new MyJmsProtocolException("Could not marshal object of type " + o.getClass().getName());
}

jaxb(java 8)中是否存在?

(免责声明:我检查了邮编对象并在此处进行了搜索和搜索,但是结果似乎加载了验证检查,应用模式等。)

我使用此

public Document JAXBObjectToDocument(Object JAXBObject) throws Exception {
    // si el objecto que recibimos en un objecto XMLRootElement, es decir el padre
    // de todo dios
    if (JAXBObject.getClass().isAnnotationPresent(XmlRootElement.class)) {
        JAXBContext jc = JAXBContext.newInstance(JAXBObject.getClass());
        Marshaller marshaller = jc.createMarshaller();
        DOMResult domResult = new DOMResult();
        marshaller.marshal(JAXBObject, domResult);
        return (Document) domResult.getNode();
    } else {
        throw new Exception("NO SE PUEDE CONVERTIR LA CLASE "" + JAXBObject.getClass().getName()
                + "" A UN "org.w3c.dom.Document"");
    }
}

i`验证我要元帅的对象是否用xmlrootelement注释

最新更新