-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve semantic options in Encoder and Decoder (#152)
A jsontext.Encoder and jsontext.Decoder could be constructed with semantic options (e.g., json.Deterministic) where such options are ignored for all encode/decode specific operations. However, allow semantic options to take effect when such an Encoder or Decoder is passed to MarshalEncode or UnmarshalDecode. The semantic option can still be overridden. One reason for this behavior is for easier migration. For example, this v1 code: dec := jsonv1.NewDecoder(in) dec.DisallowUnknownFields() for { ... := dec.Decode(...) } can be migrated as: dec := jsontext.NewDecoder(in, json.RejectUnknownMembers(true)) for { ... := json.UnmarshalDecode(dec, ...) } Notice that RejectUnknownMembers does not need to be repeatedly passed to every UnmarshalDecode call because it is implicitly stored on the Decoder. The alternative behavior is to have the construction of an Encoder or Decoder explicitly drop any semantic options. However, this seems like extra work for no benefit.
- Loading branch information
Showing
4 changed files
with
250 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.