Marshal an attribute as a type of list like nested root element using JAXB

I want to save a list of hospitals using JAXB API, every hospital has own list of services. For doing that i had implemented the following classes

public class Wrapper {

private List items = new ArrayList();


public List getItems() {

return items;






public class Hopital {

private int id;

private String nom,adresse,categorie="";


private List services=new ArrayList<>();

private static List liste=new ArrayList<>();

static File springDir;

static JAXBContext context;

static BufferedWriter writer = null;


//getters and setters

public static void addHopital(Hopital ... hops) throws Exception{

File hfile = new File("hopitaux.xml");

Wrapper hopitaux = new Wrapper();

for (int i = 0; i < hops.length; i++) {




Read More »

By: StackOverFlow - Monday, 16 April

Related Posts