JuliaData / JuliaData/StructTypes.jl

Error while deserializing when type has excluded fields (support excludes for struct)

Open
#104 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.