62,616
社区成员
发帖
与我相关
我的任务
分享
@JacksonXmlRootElement(localName = "ROOT")
public class XmlEntity {
@JacksonXmlProperty(localName = "Name")
@JacksonXmlCData(value = true)
private String Name;
@JacksonXmlProperty(localName = "Country")
@JacksonXmlCData(value = true)
private String Country;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCountry() {
return Country;
}
public void setCountry(String country) {
Country = country;
}
}
public class XmlTest {
@Test
public void testXml() throws JsonProcessingException {
XmlEntity xmlEntity = new XmlEntity();
xmlEntity.setName("wuxiongliu");
xmlEntity.setCountry("china");
String xmlStr = new XmlMapper().writeValueAsString(xmlEntity);
System.out.println(xmlStr);
}
}
<ROOT xmlns=""><country>china</country><name>wuxiongliu</name><Name><![CDATA[wuxiongliu]]></Name><Country><![CDATA[china]]></Country></ROOT>