티스토리 뷰
728x90
반응형
SMALL
Java JAXB Marshalling / UnMarshalling
1. Marshalling (POJO to xml)
Value Object Class
@Setter @XmlRootElement public class TestValue { @XmlElement public String name; @XmlElement public int age; }
Marshalling
TestValue testValue = new TestValue(); testValue.setAge(30); testValue.setName("name"); JAXBContext context = JAXBContext.newInstance(TestValue.class); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(testValue, new File("test.xml"));
위에서 생성한 test.xml 파일의 내용
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <testValue> <name>name</name> <age>30</age> </testValue>
Unmarshalling ( xml to POJO)
TestValue testValue = new TestValue(); testValue.setAge(30); testValue.setName("name"); File file = new File("test.xml"); JAXBContext context = JAXBContext.newInstance(TestValue.class); Unmarshaller unmarshaller = context.createUnmarshaller(); TestValue testObject = (TestValue) unmarshaller.unmarshal(file);
728x90
반응형
LIST
'Spring boot study > 8. ETC..' 카테고리의 다른 글
Spring Batch 정리 (0) | 2021.06.17 |
---|---|
Spring Scheduler 를 사용하여 Scheduling (0) | 2021.06.16 |
Java Gson Library Serialize / Deserialize (0) | 2021.06.09 |
Java Jackson ObjectMapper 를 이용한 Serialize / Deserialize (0) | 2021.06.09 |
JPA Auditing으로 created, modified 시간 자동화. (0) | 2021.02.04 |
댓글