Monday, 24 March 2014

Marshaling java code to xml using JaxBContext

try {

 File file = new File("C:\\file.xml");
 JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
  Marshaller jaxbMarshaller = jaxbContext.createMarshaller();   // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);   jaxbMarshaller.marshal(customer, file);
 jaxbMarshaller.marshal(customer, System.out);

    } catch (JAXBException e)  
{
e.printStackTrace();
  }    
}

No comments:

Post a Comment