-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populate sigs.k8s.io/json #1
Conversation
c0d26d9
to
af560dc
Compare
e3a002f
to
c53f720
Compare
I'm happy with this. Squash in your fix commits and I'm good to lgtm |
mkdir -p internal/golang/encoding/json tmpdir=$(mktemp -d -t golang.XXXXX) git clone --depth 1 --branch go1.17.1 git@github.com:golang/go.git $tmpdir cp -fr "${tmpdir}/src/encoding/json/*" "internal/golang/encoding/json/"
This ensures compatibility with target objects making use of stdlib exported types like RawMessage, or error return values making use of exported types like InvalidUnmarshalError
Using NewDecoder().Decode() adds ~10 additional allocs and ~doubles memory consumption for callers which already have []byte data over use of Unmarshal(), due to the Decoder only accepting a reader and then immediately reading the data into an internal buffer. To avoid that cost, this commit exposes the ability to set decoder options while using Unmarshal().
This commit adds the ability to distinguish "strict" errors, and treats unknown fields (as enabled by DisallowUnknownFields()) as a strict errors. Strict errors have the following behavior: - strict errors do not short-circuit Unmarshal() or change what is stored in the provided value - strict errors are only returned if Unmarshal() was otherwise successful (syntax errors or type errors take precedence) - strict errors are accumulated and deduped (up to an internal limit) - strict errors are returned in an instance of *UnmarshalStrictError
fc1fdb3
to
903b0d2
Compare
This adds a CaseSensitive decoder option (defaulting to false). When decoding a JSON object to a struct, JSON keys are treated case-sensitively when locating corresponding struct fields. Keys must exactly match `json` tag names (for tagged struct fields) or struct field names (for untagged struct fields), or are treated as unknown fields.
This adds a PreserveInts decoder option (defaulting to false). When decoding JSON numbers to interface{} fields, numbers are decoded as int64 when possible, falling back to `float64` on any error.
This adds a DisallowDuplicateFields decoder option (defaulting to false). Duplicate JSON object keys encountered produce strict errors. - When decoding to a struct, duplicate keys are keys that map to the same struct field. - When decoding to a map, duplicate keys are identical strings (case-sensitive). Duplicate detection is implemented as inlined closures to minimize heap allocs.
…coderCaseSensitivePreserveInts
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Best reviewed commit by commit
UnmarshalCaseSensitivePreserveInts
,UnmarshalStrict
, andNewDecoderCaseSensitivePreserveInts
functionsbenchmarks vs stdlib with strict error checking additions: