bobymaiky / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

should not always use toString() as fallback in JSONValue.writeJSONString() #99

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in this example:

enum X {T};
List<X> ls = Arrays.asList(X.T);

trying to jsonify ls will yield an invalid JSON string: "[T]".

would it be better to provide the option to use escaped toString() as a 
fallback?

Original issue reported on code.google.com by w3c...@gmail.com on 3 Sep 2014 at 9:45

GoogleCodeExporter commented 8 years ago
Thank you for pointing it out.

It behaves like this because of backward compatibility: Some user may override 
toString() to generate their own JSON literal, which cannot be escaped to a 
JSON string or the customization will not work. Although later we suggest to 
use toJSONString() in JSONAware interface to generate custom JSON literal 
instead, we don't want to break any previous codes in user's environment.

Original comment by fangyid...@gmail.com on 4 Sep 2014 at 5:05

GoogleCodeExporter commented 8 years ago
but is it possible to provide an optional argument in writeJSONString() to 
choose the fallback behavior?

like, by default use toString() but if it's invoked like writeJSONString(obj, 
true) then use escaped toString()?

Original comment by w3c...@gmail.com on 4 Sep 2014 at 5:44