[英]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. 嗨,通过以下链接,我能够将JAXB转换为java对象,并使用下面的语句在控制台中打印它。
http://www.mkyong.com/java/jaxb-hello-world-example/ 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) ex)log.info(客户)或log.debug(客户)
I am using Apache log4j.Does anyone have any idea?? 我正在使用Apache log4j。有没有人有任何想法?
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.