Hi by following the below link i am able to convert JAXB to java object and print it in console using below statement.
http://www.mkyong.com/java/jaxb-hello-world-example/
jaxbMarshaller.marshal(customer, System.out);
But i want to print the output in logger.
ex)log.info(customer) or log.debug(customer)
I am using Apache log4j.Does anyone have any idea??
In JAXB, marshalling involves parsing an XML content object tree and writing out an XML document that is an accurate representation of the original XML document, and is valid with respect the source schema. JAXB can marshal XML data to XML documents, SAX content handlers, and DOM nodes.
A: The JAXB Specification currently does not address the thread safety of any of the runtime classes. In the case of the Oracle JAXB RI, the JAXBContext class is thread safe, but the Marshaller , Unmarshaller , and Validator classes are not thread safe.
Below a possible way..
Customer customer = new Customer();
//set customer attributes
JAXBContext jc = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = jc.createMarshaller();
StringWriter stringWriter = new StringWriter();
marshaller.marshal(customer, stringWriter );
log.info(stringWriter.toString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With