Closed RongkunWang closed 4 months ago
@RongkunWang Hi, thanks for the PR! Looks good, but can you handle this case too?
using Serde
j = """
{
"z":1,
"x": null
}
"""
struct DataN
z::Int
x::Union{String,Nothing}
end
struct DataM
z::Int
x::Union{String,Missing}
end
julia> Serde.deser(DataN, Serde.parse_json(j, null = nothing))
DataN(1, nothing)
julia> Serde.deser(DataN, Serde.parse_json(j, null = missing))
ERROR: WrongType: for 'DataN' value 'missing' has wrong type 'x::Missing', must be 'x::Union{Nothing, String}'
julia> Serde.deser(DataM, Serde.parse_json(j, null = nothing))
DataM(1, missing)
julia> Serde.deser(DataM, Serde.parse_json(j, null = missing))
DataM(1, missing)
Hi @gryumov ,
I see, the nulltype()
will always be the correct type from the union so I should have just used that with your suggestion.
So now I'm applying the same technique for the other dispatch of deser
.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 71.72%. Comparing base (
7f36b84
) to head (125c89a
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@RongkunWang, thanks for the bug fix
First attempt to contribute to a Julia package. Fix #47.
Used the code in the issue to create a test.
Pull request checklist