Skip to content

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

Merged
merged 3 commits into from
Apr 16, 2021

Conversation

david-driscoll
Copy link
Member

No description provided.

@david-driscoll david-driscoll added the bug Something isn't working label Apr 15, 2021
@david-driscoll david-driscoll enabled auto-merge (squash) April 15, 2021 22:46
@github-actions github-actions bot added this to the v0.19.1 milestone Apr 15, 2021
@rjmholt
Copy link
Contributor

rjmholt commented Apr 15, 2021

Thanks @david-driscoll!

@rjmholt
Copy link
Contributor

rjmholt commented Apr 15, 2021

Fixes #562

Comment on lines 16 to 19
( 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)
Copy link
Contributor

@rjmholt rjmholt Apr 15, 2021

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?

Copy link
Member Author

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

@david-driscoll david-driscoll disabled auto-merge April 16, 2021 01:53
@codecov
Copy link

codecov bot commented Apr 16, 2021

Codecov Report

Merging #564 (337aa64) into master (1b6788d) will decrease coverage by 3.82%.
The diff coverage is 40.00%.

❗ Current head 337aa64 differs from pull request most recent head 4abdcc1. Consider uploading reports for the commit 4abdcc1 to get more accurate results
Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...erialization/Converters/EnumLikeStringConverter.cs 62.50% <40.00%> (-20.84%) ⬇️
src/JsonRpc/ExternalServiceProvider.cs 50.00% <0.00%> (-50.00%) ⬇️
src/JsonRpc.Generators/SymbolExtensions.cs 71.42% <0.00%> (-28.58%) ⬇️
src/Dap.Client/ProgressObservable.cs 0.00% <0.00%> (-22.23%) ⬇️
src/JsonRpc/Server/ContentModifiedException.cs 37.50% <0.00%> (-18.75%) ⬇️
src/JsonRpc/Server/RequestCancelledException.cs 37.50% <0.00%> (-18.75%) ⬇️
...rver/Configuration/ChainedConfigurationProvider.cs 58.62% <0.00%> (-17.25%) ⬇️
...ient/Configuration/ChainedConfigurationProvider.cs 0.00% <0.00%> (-17.25%) ⬇️
...rver/Configuration/ChainedConfigurationProvider.cs 0.00% <0.00%> (-17.25%) ⬇️
src/JsonRpc/Server/ServerErrorResult.cs 83.33% <0.00%> (-16.67%) ⬇️
... and 111 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b6788d...4abdcc1. Read the comment docs.

@david-driscoll david-driscoll merged commit 5d71f00 into master Apr 16, 2021
@david-driscoll david-driscoll deleted the fix/path-format branch April 16, 2021 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants