-
Notifications
You must be signed in to change notification settings - Fork 105
Fixed a bug where nullable enum like classes could not be deserialized correctly #564
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
Conversation
Thanks @david-driscoll! |
Fixes #562 |
( reader.TokenType, Nullable.GetUnderlyingType(objectType) ) switch { | ||
(JsonToken.String, null) => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value), | ||
(JsonToken.String, { } realType) => (IEnumLikeString) Activator.CreateInstance(realType, (string) reader.Value), | ||
_ => (IEnumLikeString) Activator.CreateInstance(objectType, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we get something like PathFormat?
(implying the value can be null
), we could see a null
from reader.Value
I assume.
I would have expected the serialiser to return null
in that circumstance rather than new PathFormat(null)
.
But also, if we do get a PathFormat?
, we can't promise a non-nullable IEnumLikeString
but rather I would have guessed we need to return IEnumLikeString?
.
So in the realType
branch, I would have expected something like:
reader.Value is null ? null : (IEnumLikeString) Activator.CreateInstance(realType, (string) reader.Value)
Does that make sense? Or is there something else going on here that makes that not a concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds correct, I'll update the pattern
Codecov Report
@@ Coverage Diff @@
## master #564 +/- ##
==========================================
- Coverage 73.40% 69.57% -3.83%
==========================================
Files 256 235 -21
Lines 12246 11809 -437
Branches 827 800 -27
==========================================
- Hits 8989 8216 -773
- Misses 3257 3377 +120
- Partials 0 216 +216
Continue to review full report at Codecov.
|
No description provided.