How to print jaxb for java object in logger

Hi, following the link below, I can convert JAXB to a java object and print it to the console using the instructions below.

http://www.mkyong.com/java/jaxb-hello-world-example/

jaxbMarshaller.marshal(customer, System.out); 

But I want to print the output in a magazine.

ex) log.info (client) or log.debug (client)

I am using Apache log4j. Does anyone have an idea?

+6
source share
1 answer

Below are the possible ways.

 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()); 
+4
source

Source: https://habr.com/ru/post/976101/


All Articles