Export to GitHub

json-simple - issue #99

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


Posted on Sep 3, 2014 by Massive Giraffe

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?

Comment #1

Posted on Sep 4, 2014 by Helpful Panda

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.

Comment #2

Posted on Sep 4, 2014 by Massive Giraffe

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()?

Status: WontFix

Labels:
Type-Defect Priority-Medium