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
|
public static void main(String[] args) {
//création d'un joueur
Joueur j1 = new Joueur();
j1.setLogin("j1");
try {
//Test : vérifier que le joueur a pour login j1(normalement devrait renvoyer true =><strong> Ok renvoi True</strong>)
System.out.println(j1.isLogin("j1"));
marshaling(j1);
Joueur jfinal =unMarshaling();
//Test : vérifier que le joueur a pour login j1 (normalement devrait renvoyer true => Ko renvoi false)
System.out.println(jfinal.isLogin("j1"));
} catch (JAXBException e) {
e.printStackTrace();
}
}
private static Joueur unMarshaling() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Joueur.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Joueur joueur = (Joueur) jaxbUnmarshaller.unmarshal( new File("C:/Users/Public/joueur.xml") );
return joueur;
}
private static void marshaling(Object o) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Joueur.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(o, new File("C:/Users/Public/joueur.xml"));
}
} |
Partager