5 ms·
For that use case, I think that you can assign your defaults before passing your target struct to the unmarshaller. The unmarshaller will iterate on the json i
by xvello 4y ago
For that use case, I think that you can assign your defaults before passing your target struct to the unmarshaller.
The unmarshaller will iterate on the json input and set struct fields when json fields are found. This means that struct fields that don't match the json are ignored, and values you have set before will be left as is.
- doctor_eval 4y agoWhile true, this approach doesn’t work for nested structs, which are instantiated by the parser.