[ Spring ] gson-xml을 통한 xml to Object 파싱
라이브러리 추가
pom.xml > dependencies > add
사용법
/** Very simple model. */
public static class SimpleModelForAttr {
private String name;
@SerializedName("@a1")
private String a1;
@SerializedName("@a2")
private int a2;
public String getName() { return name; }
public String getA1() { return a1; }
public int getA2() { return a2; }
}
@Test
public void attributesAndSkipTest() {
// description must be skipped
final String xml = "<model a1=\"a\" a2=\"2\"><name>my name</name><description>my description</description></model>";
final SimpleModelForAttr model = createGson().fromXml(xml, SimpleModelForAttr.class);
assertEquals("my name", model.getName());
assertEquals("a", model.getA1());
assertEquals(2, model.getA2());
}
https://github.com/stanfy/gson-xml/blob/master/src/test/java/com/stanfy/gsonxml/test/SimpleXmlReaderTest.java