JuliaData / JuliaData/StructTypes.jl
Error while deserializing when type has excluded fields (support excludes for struct)
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 86
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
@kwdef struct Person
name::String
fingers::Int=2
end
StructTypes.excludes(::Type{Human}) = (:fingers,)
In the above example, JSON3.write(Person("John")) returns {"name":"John"} as expected. However when we deserialize, we get Cannot `convert` an object of type Nothing to an object of type Int. Instead of setting fingers to nothing, it should probably call a constructor without fingers so that it sets default value 2?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Person example and trace how StructTypes.excludes(::Type{Human}) is handled during deserialization after JSON3.write omits fingers. Inspect the deserialization path that converts the missing field, then verify that an excluded field uses the constructor's default value rather than converting nothing to Int. Done when the example deserializes successfully with fingers set to 2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100