forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJAXBExperiments.java
More file actions
34 lines (29 loc) · 1.04 KB
/
Copy pathJAXBExperiments.java
File metadata and controls
34 lines (29 loc) · 1.04 KB
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
28
29
30
31
32
33
34
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class JAXBExperiments
{
public static void main( String [] args ) throws JAXBException
{
Inventory inventory = new Inventory();
Animal animal = new Gorilla();
animal.animalClass= Animal.AnimalClass.mammal;
animal.name = "Song Fang";
animal.species = "Giant Panda";
animal.habitat = "China";
animal.food = "Bamboo";
animal.temperament = "Friendly";
animal.weight = 45.0;
FoodRecipe recipe = new FoodRecipe();
recipe.name = "Gorilla Chow";
recipe.ingredient.add( "leaves" );
recipe.ingredient.add( "insects" );
recipe.ingredient.add( "fruit" );
animal.foodRecipe = recipe;
inventory.animal.add( animal );
JAXBContext context = JAXBContext.newInstance( Inventory.class );
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(inventory, System.out);
}
}