Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Created October 24, 2010 09:43
Show Gist options
  • Save chbaranowski/643397 to your computer and use it in GitHub Desktop.
Save chbaranowski/643397 to your computer and use it in GitHub Desktop.
JAXB Demo Test SWQS
import java.io.File;
import javax.xml.bind.JAXB;
import org.junit.Test;
import static org.junit.Assert.*;
public class CustomerModelTest {
@Test
public void testSaveLoadCustomerModel_JAXB() throws Exception {
CustomerModel customerModel = new CustomerModel();
customerModel.setName("Christian");
customerModel.setLastname("Baranowski");
// speichert das Objekt customerModel in die XML Datei sample.xml
JAXB.marshal(customerModel, new File("sample.xml"));
// Inhalt des XML sieht wie folgt aus:
// <customerModel>
// <name>Baranowski</name>
// <firstname>Christian</firstname>
// </customerModel>
// lädt das Objekt loadCustomerModel aus dem XML Inhalt der Datei sample.xml
CustomerModel loadCustomerModel = JAXB.unmarshal(new File("sample.xml"), CustomerModel.class);
assertEquals("Christian", loadCustomerModel.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment