updating read for StructTypes.Mutable()
rapus95 opened this issue · comments
I have a situation like that:
Base.@kwdef mutable struct PublisherConfig
CIName::String = "Test"
CIFileName::String = "CI.yml"
SSHSecretName::String = "SSH_private_access"
end
JSON3.StructType(::Type{PublisherConfig}) = JSON3.StructTypes.Mutable()
const CONFIG = PublisherConfig()
Now, the assignment in the last line is important because it shall be a const. the const is important for performance. Thus, what I'm missing is an option to update the pre-existing object from JSON3 (rather than having JSON3 create a new one)
Ah, that does seem useful. I don't think it would actually be very hard to support; we could introduce a JSON3.read!(json, x::T)
public function to essentially "populate x
" from fields found in json. Internally, it would also not be a ton of work, because we'd make the main JSON3.read
for mutables take an existing x::T
, which JSON3.read!
would call directly, and JSON3.read
would just create a x = T()
and pass it to the same. Feel like taking a stab at it?
Implemented in #79