Repository navigation
Conversation
Unmarshal stored any decoded JSON value into a target of a basic type: a string into a bool, a bool into an int, and nil for null. A later reflect.Value.Bool on such a field panicked with "call of reflect.Value.Bool on bool Value", as for an app that decodes the saved values of a field after its type changed. As in Go, a JSON value of another type leaves the target unchanged, the other values are decoded, and the first such value is returned as an *UnmarshalTypeError, which is now registered for type assertions. A null leaves the target unchanged, and is the zero value for an element of a slice or map. Named basic types keep their decoding, as they can decode with their methods, such as UnmarshalText. Add the package_import_encoding_json_unmarshal_type_errors compliance test, of top-level values, struct fields, slice elements, and a field of a struct made with reflect.StructOf. Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unmarshal stored any decoded JSON value into a target of a basic type: a string into a bool, a bool into an int, and nil for null. A later reflect.Value.Bool on such a field panicked with "call of reflect.Value.Bool on bool Value", as for an app that decodes the saved values of a field after its type changed.
As in Go, a JSON value of another type now leaves the target unchanged, the other values are decoded, and the first such value is returned as an *UnmarshalTypeError, which is now registered for type assertions, like *SyntaxError. A null leaves the target unchanged, and is the zero value for an element of a slice or map. Named basic types keep their decoding, as they can decode with their methods, such as UnmarshalText. A field with the string tag option, which is not supported, keeps its current decoding. With UseNumber, numbers are decoded as the text of their literals, so a string is accepted for a number then.
The new package_import_encoding_json_unmarshal_type_errors compliance test covers top-level values, struct fields, slice elements, and a field of a struct made with reflect.StructOf. The full compliance suite, typecheck, and the encoding/json vitest tests pass.