Sérialiser plusieurs instances de la même classe
Bonjour,
Voici le code de la classe que je sérialise dans un fichier XML:
Code:
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 35 36 37 38 39 40 41
| @XmlRootElement(name = "Appel")
@XmlAccessorType (XmlAccessType.FIELD)
public class TypeAppel {
private String id;
private String typeAppel;
private String objMail;
public String getId() {
Utils u = new Utils();
id = u.getGUID();
return id;
}
public String getTypeAppel() {
return typeAppel;
}
public void setTypeAppel(String typeAppel) {
this.typeAppel = typeAppel;
}
public String getObjMail() {
return objMail;
}
public void setObjMail(String objMail) {
this.objMail = objMail;
}
public TypeAppel() {
this.typeAppel = null;
this.objMail = null;
}
public TypeAppel(String typeAppel, String objMail) {
this.typeAppel = typeAppel;
this.objMail = objMail;
}
} |
J'ai une deuxième classe qui sert à avoir une liste de types d'appels:
Code:
private List<TypeAppel> listTypeAppel = new ArrayList<>();
J'obtiens donc le code XML suivant:
Code:
1 2 3 4 5 6 7
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ListTypAppels>
<TypeAppel>
<typeAppel>normal</typeAppel>
<objMail>N</objMail>
</TypeAppel>
</ListTypAppels> |
Si un type d'appel est déjà sauvé et qu'il faut en ajouter un nouveau, faut-il recréer le fichier dans son entièreté? Ou, avec JAXB, est-il possible de sérialiser une nouvelle instance de la classe tout en préservant ce qui est déjà dans le fichier? Si oui, pouvez-vous m'éclairer sur la façon de procéder?
Merci d'avance.