|potential bug in moxy. Object unmarshalled in Binder doesn't match object from Unmarshaller [message #1793024]
||Fri, 27 July 2018 21:17
| Steven Boscarine
Registered: July 2018
I am trying to do what Blaise wrote about in |
h t t p : //blog.bdoughan.com/2010/09/jaxb-xml-infoset-preservation.html I have a complex set of bindings to a complex XML schema.
Using the same String as input, I can correctly unmarshall the XML to my object with:
//Object returned shows all elements correctly.
return (Configs) ctx.createUnmarshaller().unmarshal(new StringReader(input));
final JAXBContext ctx = GenericJAXBWrapper.initCtx(AccountInfo.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new ByteArrayInputStream(in.getBytes()));
Binder<Node> binder = ctx.createBinder();
AccountInfo configs = (AccountInfo) binder.unmarshal(document);
//This object is empty.
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
final StringWriter buf = new StringWriter();
t.transform(new DOMSource(document), new StreamResult(buf));
//The XML returned is actually correct.
Is there any obvious mistake on my part? I changed my javax.xml.bind.context.factory in jaxb.properties and the code works great for a very simple schema, including preserving the comments and unrecognized elements like Blaise wrote about (didn't work in the default Java 8 JAXB as you probably know). However, the complex example is not unmarshalled correctly using the binder, but the Unmarshaller interface works fine.
I tried this on eclipselink 2.7.1 and 2.5.0.
Am I misusing the API?
Thanks so much!
Powered by FUDForum
. Page generated in 0.01880 seconds