-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSONObject.toString does not use an Enum's toString()
but its name()
#838
Comments
Hi can I work on this? |
@ThestralWarrior Sure, there are no restrictions on who gets to work on tickets. I don't know of anyone else working on this, so feel free to get started. Please keep in mind that changes to existing behavior are disallowed, unless there is a compelling reason for the change. |
…ridden toString() method for enum values instead of name().
This is not a bug and was the intended way for enums to be serialized and deserialised by this library. This would be a major breaking change for anyone who is using the enum feature |
I understand. It's my first time trying to make an open source contribution. I could use some guidance! |
@ThestralWarrior No worries, this was an unusual issue since the obvious solution was not right for this project. There will be other opportunities to contribute. |
What is the workaround for this problem? JSONObject is treating Enum differently than any other class. If a user wants to serialize and deserialize an enum value using something other than I see https://github.com/stleary/JSON-java/wiki/Tech:-How-to-solve-specific-problems-in-your-JSON-Java-code which talks about implementing |
@robross0606 This is how the library was designed; there is no workaround. It may be possible for a future release to provide an option for alternative handling using a JSONParserConfiguration object and toString(), , but the support for that is not in place yet. |
When calling the
toString
method of aJSONObject
, if a field of the object is an enum, thename
method is called (when constructing the string) instead of thetoString
method. This is problematic asname()
is not overidable (as it is decalred final) whereastoString
is.I have found where this is in the sources.
Furthermore, it is specified in the java doc of the
name
function :The fix should be really easy, I can do it if it helps you. Is this an issue not tracked ? I have not found corresponding issues.
Here's a quick way to reproduce this default.
Thanks in advance,
Arthur
The text was updated successfully, but these errors were encountered: