Main.java

Download Main.java

 1: package com.wpollock.jaxbdemo;
 2: 
 3: import javax.xml.bind.*;
 4: import java.io.*;
 5: import java.math.BigDecimal;
 6: 
 7: public class Main {
 8:     public static void main ( String[] args ) throws JAXBException, FileNotFoundException {
 9:         Long longId = 10L;
10:         User user = new User(longId, "Hymie", "HPiffl@wpollock.com");
11:         Product product = new Product("PO1", "HCC Coffee Mug",
12:                 "https://images.hccfl.edu/mug.jpg", new BigDecimal(7.99), user);
13:         JAXBContext jaxbContext = JAXBContext.newInstance(Product.class);
14:         Marshaller marshaller = jaxbContext.createMarshaller();
15:         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
16:         File file = new File("product.xml");
17:         marshaller.marshal(product, file);
18:         System.out.println("Generated \"" + file.getAbsolutePath() + "\".");
19:         marshaller.marshal(product, System.out);
20:     }
21: }