4
版本: 1.2.67
报错信息:
原 Object JSON化后:{
"bbbb\"":{
"x":"x"
},
"aaaa\"":{"$ref":"$.bbbb\\""}
}
反序列化失败!
com.alibaba.fastjson.JSONException: unclosed string :
at com.alibaba.fastjson.parser.JSONLexerBase.scanString(JSONLexerBase.java:893)
at com.alibaba.fastjson.parser.JSONLexerBase.nextToken(JSONLexerBase.java:109)
at com.alibaba.fastjson.parser.JSONLexerBase.nextToken(JSONLexerBase.java:360)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:406)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:565)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1401)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1367)
at com.alibaba.fastjson.JSON.parse(JSON.java:170)
at com.alibaba.fastjson.JSON.parse(JSON.java:180)
at com.alibaba.fastjson.JSON.parse(JSON.java:149)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:241)
at TestRefWithQuote.main(TestRefWithQuote.java:35)
测试原码:
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class TestRefWithQuote {
public static class X {
private String x;
public X(String x) {
this.x = x;
}
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
}
public static void main(String[] args) {
Map<String, X> origin = new HashMap<>();
X x = new X("x");
origin.put("aaaa\"", x);
origin.put("bbbb\"", x);
// String json = JSON.toJSONString(cache, SerializerFeature.DisableCircularReferenceDetect);
String json = JSON.toJSONString(origin, true);
System.out.println("JSON:\n" + json);
try {
JSONObject target = JSON.parseObject(json);
System.out.println("反序列化成功!");
} catch (Exception e) {
System.out.println("反序列化失败!");
e.printStackTrace();
}
}
}