Issue 99 in json-simple: should not always use toString() as fallback in JSONValue.writeJSONString()

4 views
Skip to first unread message

json-...@googlecode.com

unread,
Sep 3, 2014, 5:46:01 PM9/3/14
to json-...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 99 by w3c...@gmail.com: should not always use toString() as
fallback in JSONValue.writeJSONString()
https://code.google.com/p/json-simple/issues/detail?id=99

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?

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

json-...@googlecode.com

unread,
Sep 4, 2014, 1:05:17 AM9/4/14
to json-...@googlegroups.com
Updates:
Status: WontFix

Comment #1 on issue 99 by fangyid...@gmail.com: should not always use
toString() as fallback in JSONValue.writeJSONString()
https://code.google.com/p/json-simple/issues/detail?id=99

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.

json-...@googlecode.com

unread,
Sep 4, 2014, 1:44:41 AM9/4/14
to json-...@googlegroups.com

Comment #2 on issue 99 by w3c...@gmail.com: should not always use
toString() as fallback in JSONValue.writeJSONString()
https://code.google.com/p/json-simple/issues/detail?id=99

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()?
Reply all
Reply to author
Forward
0 new messages