forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJaxbWriter.java
More file actions
27 lines (22 loc) · 777 Bytes
/
Copy pathJaxbWriter.java
File metadata and controls
27 lines (22 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package xml.jaxbexample;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.File;
/**
* Created by max on 2/22/17.
*/
public class JaxbWriter {
public static void main(String[] args) throws JAXBException {
Customer customer = new Customer();
customer.setId(1);
customer.setName("Max");
customer.setAge(29);
File file = new File("/home/max/file.xml");
JAXBContext context = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(customer, file);
marshaller.marshal(customer, System.out);
}
}