| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…e Enums. The new way enums are handled is to always place the actual enum in the JSONObject/JSONArray. When writing, we always write the actual "name" of the enum, so even with a toString override on the enum class, the value remains consistant and compatible with the optEnum/getEnum methods. The constructor JSONObject(Object) functions the same way as before when passing an enum and is consistent with other "value" types. For example, when creating a JSONObject with Long, Boolean, BigDecimal as the constructor parameter, the value will be treated as a "bean".
|
Thanks, will take a look at this tonight. Please add a Risk section with your evaluation of the risk of this change. You can see examples in #259 and #261. For example, in what ways might existing users be impacted by the functional change? Agreed that enums are currently not well supported. |
Sorry, something went wrong.
|
done. |
Sorry, something went wrong.
|
Is there a reasonable way to implement this such that existing users are unaffected, but new users can choose the new behavior? |
Sorry, something went wrong.
|
I don't think so since it was inconsistent. Sometimes values would be On Aug 12, 2016 01:49, "Sean Leary" notifications@github.com wrote:
|
Sorry, something went wrong.
|
Enum support is connected in an odd way to BigNumber: both are Java features that did not exist when the lib was first implemented. At the times we added support for both, Douglas gave us pretty clear guidance on what we should and should not do, when implementing support for new features. That is, it needs to be exactly correct, and it can't break existing code. Of course, there will be a little give and take between those two constraints. I am still trying to get a sense of whether this enhancement is within the gray area ("Some rules can be bent; some can be broken" - Morpheus), or if we are straying too far into the realm of breaking existing code. I am going to be working all weekend - chores and job. Anything you can do to nail down precisely what is going to change, plus any discussion you want to throw in, would be humbly appreciated. |
Sorry, something went wrong.
|
I'd say that since the current implementation is inconsistent that this is On Aug 13, 2016 02:45, "Sean Leary" notifications@github.com wrote:
|
Sorry, something went wrong.
|
Also to note, this library did have support for enums a while ago, but On Aug 13, 2016 09:09, "John Aylward" john@johnanddalene.net wrote:
|
Sorry, something went wrong.
|
Good information, thanks. Would that be the change and revert to JSONObject.wrap() in 2012? Or was there more? |
Sorry, something went wrong.
|
Yes, just those 2 commits as far as I know. One in July adding support, On Aug 13, 2016 12:35, "Sean Leary" notifications@github.com wrote:
|
Sorry, something went wrong.
|
Taking small steps...
Let me know what you think. |
Sorry, something went wrong.
|
That sounds good. The changes to valueToString are indeed needed to prevent For the number changes, I'll revert those here and place them in a separate On Aug 15, 2016 02:01, "Sean Leary" notifications@github.com wrote:
|
Sorry, something went wrong.
|
ok, cleanup up the commit as well as merging in the latest changes you made for the comments. Also updated my notes in comment#1 |
Sorry, something went wrong.
|
Thanks, starting a 3 day comment window. |
Sorry, something went wrong.
Revert Enum changes introduced in upstream pull request stleary#271 and revert the Enum unit tests to how they were around PR stleary#127 on 2015-07-08. This reintroduces the original JSON-java Enum handling that did not have explicit handling for Enums and handled them inconsistently between JSONObject and JSONArray, and also relied on Enum.toString() when wrapping them instead of storing them as value and serializing them to their Enum.name() value.
| Back | FazBrowse Home | New Git URL |
Adds support to JSONObject wrap and write methods to explicitly handle Enums.
What problem does this code solve?
Enums were handled inconsistently as noted in the original improvement (#140 and #127) and brought up again in #145 and #255
The new way enums are handled is to always place the actual enum in the JSONObject/JSONArray (not wrapped, similar to other value types). When writing, we always write the actual "name" of the enum, so even with a toString override on the enum class, the value remains consistent and compatible with the optEnum/getEnum methods.
The constructor JSONObject(Object) functions the same way as before when passing an enum and is consistent with other "value" types. For example, when creating a JSONObject with Long, Boolean, BigDecimal as the constructor parameter, the value will be treated as a "bean".
Risks
Low risk. Currently inserting enums into JSONObject and JSONArray are not consistent. Anyone depending on the existing handling of enums probably does so with if blocks to ensure they have the correct data. Additionally, some cases of inserting an enum would produce results that could not be read back using get|optEnum methods.
Given that the data is not always reversible, it's unlikely that people are depending on this behaviour.
Changes to the API?
No, but there are functional changes
Will this require a new release?
Can be rolled into the next release, pending comments.
Should the documentation be updated?
Not required.
Does it break the unit tests?
Yes, new unit tests have been added.
Review status
ACCEPTED. Starting 3-day comment window 15 Aug 2016