我在Java类中有一个强大的枚举: public enum FinalResponse {
THING_1("Thing1") {
@Override
String getDescription() {
return "Based on what you've told us so far, it’s likely ; (it goes on)
}
@Override
String getApplyUrl() {
return "https://www.theinternet.com";
}
},
当我从下面的类中调用getDescription时:
class FinalResponseMaker {
FinalResponseMaker() {}
static String getResponse(FinalResponse response) {
def output = JsonOutput.toJson([[
code: response.getCode(),
description: response.getDescription(),
apply_url: response.getApplyUrl()]])
JsonOutput.prettyPrint(output)
}
}
此代码的输出包含字符串
it\u2019s likely,
即由于某种原因,“它的”中的反转逗号已经变成了它的unicode字符。
为什么呢?我怎么能让这个停止发生?
我尝试过使用
def pretty = JsonOutput.prettyPrint(output)
def unescaped = JsonOutput.unescaped(pretty)
return unescaped
但这不起作用。任何帮助都会很棒,谢谢
答案 0 :(得分:1)
这不是世界上最漂亮的解决方案,但是......
description: new String(response.getDescription().getBytes("UTF8"))
这应该确保你不会得到任何逃脱的malarky。