Xstream with special characters.

I'm working with XStream but I have a problem with the special characters á,é,í,ó,ú and ñ. I tried this: String charset = "UTF-8"; xstream = new XStream(new DomDriver(charset)); (don't work) I found that [XStream does no character encoding by itself, it relies on the configuration of the underlying XML writer. By default it uses its own PrettyPrintWriter which writes into the default encoding of the current locale. To write UTF-8 you have to provide a Writer with the appropriate encoding yourself.][1] My problem is that I don't know how to provide a Writer... [1]: http://x-stream.github.io/faq.html // get the model from the map passed created by the controller Object model = map.get("model"); Object viewData = transformViewData(model); //TEST Writer w = new OutputStreamWriter(viewData, "UTF-8"); //FINTEST // if the model is null, we have an exception String xml = null; if (viewData != null){ xml = xstream.toXML(viewData, w); //Err:Cannot find symbol... }else{ // so render entire map xml = xstream.toXML(map, w); //Err:Cannot find symbol... } response.getOutputStream().write(xml.getBytes());

以上就是Xstream with special characters.的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准