I would like to be able to set the indentation to a number of spaces when storing with XStream. I have seen this SO post and I'm afraid it's not quite clear how to set the number of spaces to use. I seem to not be getting something. Could somebody kindly explain this and illustrate it with an example?

有帮助吗?

解决方案

Following the example in the post you've linked to and the API, I came up with this code:

char[] indent = new char[] { ' ', ' ', ' ', ' ' };
BufferedOutputStream stdout = new BufferedOutputStream(System.out);
xstream.marshal(object, new PrettyPrintWriter(new OutputStreamWriter(stdout), indent));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top