XStream : node with attributes and text node?

后端 未结 4 784
难免孤独
难免孤独 2020-12-09 03:59

I would like to serialize an object to an XML of this form with XStream.

text

The value of the node

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 04:41

    you can use a predefined Converter.

    @XStreamAlias("node")
    @XStreamConverter(value=ToAttributedValueConverter.class, strings={"text"})
    class Node {
      private String att;
      private String text;
    }   
    

    XStream Annotations Tutorial also says that for att attribute:

    Note, that no XStreamAsAttribute annotations were necessary. The converter assumes it implicitly.

提交回复
热议问题