diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..2a6d5c4 --- /dev/null +++ b/flags.go @@ -0,0 +1,9 @@ +package json + +import ( + "github.com/go-json-experiment/json/internal/jsonflags" +) + +type ( + BoolFlags = jsonflags.Bools +) diff --git a/internal/jsonflags/flags.go b/internal/jsonflags/flags.go index c2473cd..9860f17 100644 --- a/internal/jsonflags/flags.go +++ b/internal/jsonflags/flags.go @@ -6,8 +6,6 @@ // These flags are shared across both "json", "jsontext", and "jsonopts". package jsonflags -import "github.com/go-json-experiment/json/internal" - // Bools represents zero or more boolean flags, all set to true or false. // The least-significant bit is the boolean value of all flags in the set. // The remaining bits identify which particular flags. @@ -17,7 +15,7 @@ import "github.com/go-json-experiment/json/internal" // - (Expand | Indent | 1) means "Expand and Indent are true" type Bools uint64 -func (Bools) JSONOptions(internal.NotForPublicUse) {} +func (Bools) JSONOptions() {} const ( // AllFlags is the set of all flags. diff --git a/internal/jsonopts/options.go b/internal/jsonopts/options.go index 6b63d5c..376780c 100644 --- a/internal/jsonopts/options.go +++ b/internal/jsonopts/options.go @@ -5,14 +5,13 @@ package jsonopts import ( - "github.com/go-json-experiment/json/internal" "github.com/go-json-experiment/json/internal/jsonflags" ) // Options is the common options type shared across json packages. type Options interface { // JSONOptions is exported so related json packages can implement Options. - JSONOptions(internal.NotForPublicUse) + JSONOptions() } // Struct is the combination of all options in struct form. @@ -72,7 +71,7 @@ func (dst *Struct) CopyCoderOptions(src *Struct) { dst.CoderValues = src.CoderValues } -func (*Struct) JSONOptions(internal.NotForPublicUse) {} +func (*Struct) JSONOptions() {} // GetUnknownOption is injected by the "json" package to handle Options // declared in that package so that "jsonopts" can handle them. @@ -170,7 +169,13 @@ func (dst *Struct) Join(srcs ...Options) { dst.FormatDepth = src.FormatDepth } default: - JoinUnknownOption(dst, src) + unknown := true + if joiner, ok := src.(interface{ Join(*Struct, Options) bool }); ok { + unknown = joiner.Join(dst, src) + } + if unknown { + JoinUnknownOption(dst, src) + } } } } @@ -184,7 +189,7 @@ type ( // type for jsonflags.Unmarshalers declared in "json" package ) -func (Indent) JSONOptions(internal.NotForPublicUse) {} -func (IndentPrefix) JSONOptions(internal.NotForPublicUse) {} -func (ByteLimit) JSONOptions(internal.NotForPublicUse) {} -func (DepthLimit) JSONOptions(internal.NotForPublicUse) {} +func (Indent) JSONOptions() {} +func (IndentPrefix) JSONOptions() {} +func (ByteLimit) JSONOptions() {} +func (DepthLimit) JSONOptions() {} diff --git a/options.go b/options.go index a43e31e..3bbd391 100644 --- a/options.go +++ b/options.go @@ -7,7 +7,6 @@ package json import ( "fmt" - "github.com/go-json-experiment/json/internal" "github.com/go-json-experiment/json/internal/jsonflags" "github.com/go-json-experiment/json/internal/jsonopts" ) @@ -69,6 +68,7 @@ import ( // // Options that do not affect a particular operation are ignored. type Options = jsonopts.Options +type OptionsStruct = jsonopts.Struct // JoinOptions coalesces the provided list of options into a single Options. // Properties set in later options override the value of previously set properties. @@ -237,8 +237,8 @@ type ( unmarshalersOption Unmarshalers ) -func (*marshalersOption) JSONOptions(internal.NotForPublicUse) {} -func (*unmarshalersOption) JSONOptions(internal.NotForPublicUse) {} +func (*marshalersOption) JSONOptions() {} +func (*unmarshalersOption) JSONOptions() {} // Inject support into "jsonopts" to handle these types. func init() {