Allow to return null on native cast #152
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue/Intent
When using the native casting introduced in v2.0 I noticed that returning
null
from theparseDatabase
method would result in error as it would still try to create an Enum instance from the returned value.My use case is a modernization of a legacy codebase (25 years old) where some blank data is stored as empty strings instead of
NULL
s in the database.So when running code like this:
Application would throw an exception on blank values (
null
or empty string).For this particular project I ended adding a
NA
enum value and defaulting to that for blank values. This is not an ideal solution as the code that relies on the Enum value, and code to persist values back needs to take account of that.Changes
This PR changes the
Casts/EnumCast
class to check fornull
values returned by userland code when using theparseDatabase
method.A new test was added. Test would fail without the changes introduced by this PR.
Breaking changes
No breaking changes.