VelNaga
VelNaga

Reputation: 3953

How to print jaxb to java object in to logger

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??

Upvotes: 10

Views: 10593

Answers (1)

Xstian
Xstian

Reputation: 8272

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());

Upvotes: 12

Related Questions