Enum valueForString methods are not consistent #91
Labels
best practice
Not a defect but something that should be improved anyway
bug
A defect in the library
REVIEW - scheduled
The reviewer has scheduled a review of this PR for the current sprint
See PR #82 for more details.
Most enum classes simply use the
name()
method to define the value of the JSON value for each particular enum value. Therefore, thevalueForString
method typically calls and returns the result of thevalueOf()
method.If
valueForString
is called with a JSON value that is not contained in the enum, thevalueOf
method will cause an IllegalArgumentException.However, in enum classes that define their own internal name to represent the JSON value, the
valueForString
method loops through all enum values and returns the value if it's found. If it's not found, it will return null.All enums should behave identically in this case, so we need to determine if the correct course of action is to throw a RuntimeException (causing a crash) or to return null.
The text was updated successfully, but these errors were encountered: