您好,通过以下链接,我可以将 JAXB 转换为 java 对象,并使用以下语句在控制台中打印它。
http://www.mkyong.com/java/jaxb-hello-world-example/
jaxbMarshaller.marshal(customer, System.out);
但我想在记录器中打印输出。
例如)log.info(客户)或 log.debug(客户)
我正在使用 Apache log4j。有人知道吗??
最佳答案
下面是一种可能的方式..
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());
关于java - 如何将 jaxb 打印到 java 对象到记录器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26139999/