[英]how to avoid jackson escaping backslash?
我设置"this\\'s my case!"
到对象的字段。
调用writeAsString
,输出为"this\\\\\\'s my case!"
。
但是我希望"this\\'s my case!"
。
我如何得到想要的东西?
public class CommonUtils {
public static ObjectMapper objectMapper = new ObjectMapper();
public static ObjectMapper getObjectMapperInstance(){
return objectMapper;
}
public static void main(String[] args) throws IOException {
CommonUtils commonUtils = new CommonUtils();
commonUtils.test();
}
public void test() throws IOException {
List<MyObject> list = new ArrayList<MyObject>();
String xx = "page://list?params={\"city\"}";
list.add(new MyObject(1,xx));
}
class MyObject{
public MyObject(int tag,String str){
this.tag = tag;
this.str = str;
}
int tag;
String str;
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}
}
上面代码的输出:
[{“ tag”:1,“ str”:“ page:// list?params = {\\\\” city \\\\“}]
我想要的是:[{“ tag”:1,“ str”:“ page:// list?params = {\\” city \\“}]
如果将字符串xx更改为
String xx = "page://list?params={\\\"city\\\"}"; //page://list?params={\"city\"}
您将获得理想的结果;
[ { "tag" : 1, "str" : "page://list?params={\"city\"}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.