xStream Annotation 注解配置

<message>
  <type>15</type>
</message>

对应的java 映射代码

@XStreamAlias("message")
class RendezvousMessage {

	@XStreamAlias("type")
	private int messageType;        
	
	private List<String> content;
	
	public RendezvousMessage(int messageType, String ... content) {
		this.messageType = messageType;
		this.content = Arrays.asList(content);
	}
	
}

 

public static void main(String[] args) {
		XStream stream = new XStream();
		xstream.processAnnotations(RendezvousMessage.class);
		RendezvousMessage msg = new RendezvousMessage(15, "firstPart","secondPart");
		System.out.println(stream.toXML(msg));
	}

 

 

 

你可能感兴趣的:(xstream)