1
我使用傑克遜2.5.2和我有一個map<String,String>
傑克遜XML序列化映射該鍵包含空格
默認情況下,傑克遜將其序列爲:
<MyObject>
<map>
<key1>value1</key1>
<key2 containing spaces>value2</key2 containing spaces>
<map>
</MyObject>
,但我希望有一個通用的XML標籤:
<MyObject>
<map>
<entry key="key1">value1</entry>
<entry key="key2 containing spaces">value2</entry>
<map>
</MyObject>
這樣我的XML標籤是通用的,可以用XSD驗證
這裏是我的測試
class MyObject {
Map map = new HashMap();
public Map getMap() { return map;}
}
// Test
ObjectMapper xmlMapper = new XmlMapper();
MyObject myObject = new MyObject();
myObject.getMap().put("key1","value1");
myObject.getMap().put("key2 containing spaces","value2");
System.out.println(xmlMapper.writeValueAsString(myObject));
是否有任何配置告訴傑克遜序列化通用XML?