Created
October 24, 2010 09:43
-
-
Save chbaranowski/643397 to your computer and use it in GitHub Desktop.
JAXB Demo Test SWQS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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