java XStream 怎么将对象无格式输出
XStream可以轻松的将一个对象转换成xml格式往往XStream会将转换后的字符串格式化变成这个样子: <?xmlversion="1.0"encod...
XStream 可以轻松的将一个对象转换成xml格式往往XStream 会将转换后的字符串格式化 变成这个样子: <?xml version="1.0" encoding="utf-8"?><message> <head> <messageId>8000022010062914015005800021</messageId> <agentId>800002</agentId> <timestamp>20100629140150</timestamp> <digest>47cb04c18aea098ee4025670711a3bea</digest> </head> <body> <scheme> <schemeId>8000020034919011</schemeId> <status>1</status> <ticket> <ticketId>2010062914013002700020</ticketId> </ticket> </scheme> <scheme> <schemeId>8000020034919010</schemeId> <status>1</status> <ticket> <ticketId>2010062914013002500019</ticketId> </ticket> </scheme> </body></message>怎么样可以让XStream转出来的字符串不带格式 即:<?xml version="1.0" encoding="utf-8"?><message><head><messageId>8000022010062914015005800021</messageId><agentId>800002</agentId><timestamp>20100629140150</timestamp><digest>dad4200bc1120a699eeef5dd0846433b</digest></head><body><scheme><schemeId>8000020034919011</schemeId><status>1</status><ticket><ticketId>2010062914013002700020</ticketId></ticket></scheme><scheme><schemeId>8000020034919010</schemeId><status>1</status><ticket><ticketId>2010062914013002500019</ticketId></ticket></scheme></body></message>
展开
2个回答
展开全部
参考
XStream xstream = new XStream();
MessageRequest messageRequest = new MessageRequest();
OutputStream output = new ByteArrayOutputStream();
xstream.marshal(messageRequest, new CompactWriter(new OutputStreamWriter(output)));
System.out.println(output);
XStream xstream = new XStream();
MessageRequest messageRequest = new MessageRequest();
OutputStream output = new ByteArrayOutputStream();
xstream.marshal(messageRequest, new CompactWriter(new OutputStreamWriter(output)));
System.out.println(output);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询