Documentation
¶
Index ¶
- func Marshal(value interface{}, opts ...Option) ([]byte, error)
- func MarshalContext(ctx context.Context, value interface{}, opts ...Option) ([]byte, error)
- func MarshalStandard(value any, opts ...Option) ([]byte, error)
- func Unmarshal(data []byte, dest interface{}, opts ...Option) error
- func UnmarshalContext(ctx context.Context, data []byte, dest interface{}, opts ...Option) error
- type Codec
- type Decoder
- type DuplicateKeyPolicy
- type FieldExcluder
- type FieldFilter
- func (f *FieldFilter) AffectsIndexes(index []int) bool
- func (f *FieldFilter) ExcludeField(path []string, index []int) bool
- func (f *FieldFilter) ExcludeIndexes(index []int) bool
- func (f *FieldFilter) ExcludePath(path []string, field string) bool
- func (f *FieldFilter) WithOptions(opts ...Option) (*FieldFilter, error)
- type FieldSelection
- type IndexedPathFieldExcluder
- type MalformedPolicy
- type MarshalInterceptor
- type MarshalInterceptors
- type MarshalSession
- type MarshalerArray
- type MarshalerObject
- type Marshaller
- type Mode
- type NameTransformer
- type NilSlicePolicy
- type NullPolicy
- type NumberPolicy
- type Option
- func WithCaseFormat(caseFormat text.CaseFormat) Option
- func WithContext(ctx context.Context) Option
- func WithDebugPathSink(sink func(PathRef)) Option
- func WithDuplicateKeyPolicy(policy DuplicateKeyPolicy) Option
- func WithExcludedFields(paths ...string) Option
- func WithFieldExcluder(excluder FieldExcluder) Option
- func WithFieldUnmarshalHook(...) Option
- func WithFormatTag(tag *format.Tag) Option
- func WithMalformedPolicy(policy MalformedPolicy) Option
- func WithMode(mode Mode) Option
- func WithNameTransformer(transformer NameTransformer) Option
- func WithNilSlicePolicy(policy NilSlicePolicy) Option
- func WithNullPolicy(policy NullPolicy) Option
- func WithNumberPolicy(policy NumberPolicy) Option
- func WithOmitEmpty(enabled bool) Option
- func WithPathFieldExcluder(excluder PathFieldExcluder) Option
- func WithPathNameTransformer(transformer PathNameTransformer) Option
- func WithPathTracking(mode PathTrackingMode) Option
- func WithPathUnmarshalHook(...) Option
- func WithScannerHooks(hooks ScannerHooks) Option
- func WithUnknownFieldPolicy(policy UnknownFieldPolicy) Option
- type Options
- type PathFieldExcluder
- type PathNameTransformer
- type PathRef
- type PathSegment
- type PathTrackingMode
- type ScannerHooks
- type SegmentKind
- type UnknownFieldPolicy
- type UnmarshalInterceptor
- type UnmarshalInterceptors
- type UnmarshalSession
- type UnmarshalerArray
- type UnmarshalerJSONArray
- type UnmarshalerJSONObject
- type UnmarshalerObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶ added in v0.9.0
Marshal marshals using context.Background unless overridden by options.
func MarshalContext ¶ added in v0.9.0
MarshalContext marshals with an explicit context.
func MarshalStandard ¶ added in v0.10.0
MarshalStandard applies field exclusion while retaining encoding/json v1 field dominance, tags and value encoding. Custom value encoders own their complete value. Formatting transforms belong to MarshalContext instead.
Types ¶
type Codec ¶ added in v0.9.0
type Codec interface {
String(*string) error
Int(*int) error
Int8(*int8) error
Int16(*int16) error
Int32(*int32) error
Int64(*int64) error
Uint(*uint) error
Uint8(*uint8) error
Uint16(*uint16) error
Uint32(*uint32) error
Uint64(*uint64) error
Float32(*float32) error
Float64(*float64) error
Bool(*bool) error
Interface(*interface{}) error
Object(UnmarshalerObject) error
Array(UnmarshalerArray) error
AddString(string)
AddInt(int)
AddInt8(int8)
AddInt16(int16)
AddInt32(int32)
AddInt64(int64)
AddUint(uint)
AddUint8(uint8)
AddUint16(uint16)
AddUint32(uint32)
AddUint64(uint64)
AddFloat32(float32)
AddFloat64(float64)
AddBool(bool)
AddNull()
AddInterface(interface{}) error
AddObject(MarshalerObject)
AddArray(MarshalerArray)
}
Codec is a unified encoder/decoder contract.
type Decoder ¶ added in v0.9.0
type Decoder interface {
String(*string) error
Int(*int) error
Int8(*int8) error
Int16(*int16) error
Int32(*int32) error
Int64(*int64) error
Uint(*uint) error
Uint8(*uint8) error
Uint16(*uint16) error
Uint32(*uint32) error
Uint64(*uint64) error
Float32(*float32) error
Float64(*float64) error
Bool(*bool) error
Interface(*interface{}) error
Object(UnmarshalerJSONObject) error
Array(UnmarshalerJSONArray) error
}
Decoder defines decode-side methods used by generic unmarshalers.
type DuplicateKeyPolicy ¶ added in v0.9.0
type DuplicateKeyPolicy int
DuplicateKeyPolicy controls duplicate object key behavior.
const ( LastWins DuplicateKeyPolicy = iota ErrorOnDuplicate )
type FieldExcluder ¶ added in v0.9.0
FieldExcluder decides whether a field should be excluded.
type FieldFilter ¶ added in v0.10.0
type FieldFilter struct {
// contains filtered or unexported fields
}
func NewFieldFilter ¶ added in v0.10.0
func NewFieldFilter(t reflect.Type, selections []FieldSelection) (*FieldFilter, error)
func (*FieldFilter) AffectsIndexes ¶ added in v0.10.0
func (f *FieldFilter) AffectsIndexes(index []int) bool
AffectsIndexes bounds presentation compilation to the selected holder graph. Fully included branches retain their original types and custom codec methods.
func (*FieldFilter) ExcludeField ¶ added in v0.10.0
func (f *FieldFilter) ExcludeField(path []string, index []int) bool
ExcludeField retains the exact JSON field index when promoted fields share a Go name. Standard encoding consumes this alongside PathFieldExcluder.
func (*FieldFilter) ExcludeIndexes ¶ added in v0.10.0
func (f *FieldFilter) ExcludeIndexes(index []int) bool
ExcludeIndexes applies the selection to a canonical structural field index. Container elements do not add indexes. The longest holder scope wins, so two occurrences of one row type remain independent. Anonymous holder prefixes stay present when they contain a selected promoted field.
func (*FieldFilter) ExcludePath ¶ added in v0.10.0
func (f *FieldFilter) ExcludePath(path []string, field string) bool
func (*FieldFilter) WithOptions ¶ added in v0.10.0
func (f *FieldFilter) WithOptions(opts ...Option) (*FieldFilter, error)
WithOptions resolves parent paths using the transformed encoder's tag and naming authority. The original standard filter remains immutable.
type FieldSelection ¶ added in v0.10.0
FieldSelection includes canonical Go fields at a canonical Go holder path. An empty Fields list selects no properties at that object. Omitted scopes leave their objects unrestricted. Selection never examines row values.
type IndexedPathFieldExcluder ¶ added in v0.10.0
type IndexedPathFieldExcluder interface {
PathFieldExcluder
ExcludeField(path []string, index []int) bool
}
IndexedPathFieldExcluder optionally supplies exact promoted-field identity to standard encoding. It uses the same parent wire paths as PathFieldExcluder.
type MalformedPolicy ¶ added in v0.9.0
type MalformedPolicy int
MalformedPolicy controls malformed JSON tolerance.
const ( Tolerant MalformedPolicy = iota FailFast )
type MarshalInterceptor ¶ added in v0.9.0
type MarshalInterceptors ¶ added in v0.9.0
type MarshalInterceptors map[string]MarshalInterceptor
type MarshalSession ¶ added in v0.9.0
type MarshalSession struct {
Buffer *bytes.Buffer
Options Options
Interceptors MarshalInterceptors
// contains filtered or unexported fields
}
func NewMarshalSession ¶ added in v0.9.0
func NewMarshalSession(options Options) *MarshalSession
func (*MarshalSession) PathRef ¶ added in v0.9.0
func (s *MarshalSession) PathRef() PathRef
func (*MarshalSession) PopPath ¶ added in v0.9.0
func (s *MarshalSession) PopPath()
func (*MarshalSession) PushField ¶ added in v0.9.0
func (s *MarshalSession) PushField(name string)
func (*MarshalSession) PushIndex ¶ added in v0.9.0
func (s *MarshalSession) PushIndex(index int)
func (*MarshalSession) Release ¶ added in v0.9.0
func (s *MarshalSession) Release()
type MarshalerArray ¶ added in v0.9.0
MarshalerArray emits array elements.
type MarshalerObject ¶ added in v0.9.0
MarshalerObject emits object fields.
type Marshaller ¶ added in v0.10.0
type Marshaller struct {
// contains filtered or unexported fields
}
Marshaller retains one configured native engine for encoding and metadata. Options and callbacks must be immutable after construction.
func NewMarshaller ¶ added in v0.10.0
func NewMarshaller(typeOf reflect.Type, opts ...Option) (*Marshaller, error)
func (*Marshaller) Marshal ¶ added in v0.10.0
func (m *Marshaller) Marshal(value interface{}) ([]byte, error)
func (*Marshaller) Wire ¶ added in v0.10.0
func (m *Marshaller) Wire() (*jsonmarshal.WireShape, error)
type NameTransformer ¶ added in v0.9.0
NameTransformer transforms field names for output and path display.
type NilSlicePolicy ¶ added in v0.9.0
type NilSlicePolicy int
NilSlicePolicy controls marshal output for nil slices.
const ( NilSliceAsNull NilSlicePolicy = iota NilSliceAsEmptyArray )
type NullPolicy ¶ added in v0.9.0
type NullPolicy int
NullPolicy controls null assignment behavior.
const ( CompatNulls NullPolicy = iota StrictNulls )
type NumberPolicy ¶ added in v0.9.0
type NumberPolicy int
NumberPolicy controls numeric coercion behavior.
const ( CoerceNumbers NumberPolicy = iota ExactNumbers )
type Option ¶ added in v0.9.0
type Option interface {
// contains filtered or unexported methods
}
Option mutates runtime options.
func WithCaseFormat ¶ added in v0.9.0
func WithCaseFormat(caseFormat text.CaseFormat) Option
func WithContext ¶ added in v0.9.0
func WithDebugPathSink ¶ added in v0.9.0
func WithDuplicateKeyPolicy ¶ added in v0.9.0
func WithDuplicateKeyPolicy(policy DuplicateKeyPolicy) Option
func WithExcludedFields ¶ added in v0.10.0
WithExcludedFields resolves canonical Go-field paths using the native marshal plans, including field aliases, casing and inline holders.
func WithFieldExcluder ¶ added in v0.9.0
func WithFieldExcluder(excluder FieldExcluder) Option
func WithFieldUnmarshalHook ¶ added in v0.9.0
func WithFormatTag ¶ added in v0.9.0
func WithMalformedPolicy ¶ added in v0.9.0
func WithMalformedPolicy(policy MalformedPolicy) Option
func WithNameTransformer ¶ added in v0.9.0
func WithNameTransformer(transformer NameTransformer) Option
func WithNilSlicePolicy ¶ added in v0.9.0
func WithNilSlicePolicy(policy NilSlicePolicy) Option
func WithNullPolicy ¶ added in v0.9.0
func WithNullPolicy(policy NullPolicy) Option
func WithNumberPolicy ¶ added in v0.9.0
func WithNumberPolicy(policy NumberPolicy) Option
func WithOmitEmpty ¶ added in v0.9.0
func WithPathFieldExcluder ¶ added in v0.9.0
func WithPathFieldExcluder(excluder PathFieldExcluder) Option
func WithPathNameTransformer ¶ added in v0.9.0
func WithPathNameTransformer(transformer PathNameTransformer) Option
func WithPathTracking ¶ added in v0.9.0
func WithPathTracking(mode PathTrackingMode) Option
func WithPathUnmarshalHook ¶ added in v0.9.0
func WithScannerHooks ¶ added in v0.9.0
func WithScannerHooks(hooks ScannerHooks) Option
func WithUnknownFieldPolicy ¶ added in v0.9.0
func WithUnknownFieldPolicy(policy UnknownFieldPolicy) Option
type Options ¶ added in v0.9.0
type Options struct {
// ExcludedFields contains canonical Go-field paths for marshal projection.
ExcludedFields []string
Ctx context.Context
Mode Mode
UnknownFieldPolicy UnknownFieldPolicy
NumberPolicy NumberPolicy
NullPolicy NullPolicy
DuplicateKeyPolicy DuplicateKeyPolicy
MalformedPolicy MalformedPolicy
PathTracking PathTrackingMode
CaseFormat text.CaseFormat
FormatTag *format.Tag
TimeLayout string
NameTransformer NameTransformer
FieldExcluder FieldExcluder
PathName PathNameTransformer
PathExcluder PathFieldExcluder
DebugPathSink func(PathRef)
FieldUnmarshalHook func(ctx context.Context, holder unsafe.Pointer, field string, value any) (any, error)
PathUnmarshalHook func(ctx context.Context, holder unsafe.Pointer, path []string, field string, value any) (any, error)
OmitEmpty bool
NilSlicePolicy NilSlicePolicy
// contains filtered or unexported fields
}
Options defines runtime behavior.
type PathFieldExcluder ¶ added in v0.9.0
PathFieldExcluder excludes fields using path segments without forcing path string joins.
type PathNameTransformer ¶ added in v0.9.0
PathNameTransformer transforms names using path segments without forcing path string joins.
type PathRef ¶ added in v0.9.0
type PathRef struct {
// contains filtered or unexported fields
}
PathRef references path segments without eager string allocation.
func (PathRef) Segments ¶ added in v0.9.0
func (p PathRef) Segments() []PathSegment
type PathSegment ¶ added in v0.9.0
type PathSegment struct {
Field string
Index int
Kind SegmentKind
}
PathSegment describes one path component.
type PathTrackingMode ¶ added in v0.9.0
type PathTrackingMode int
PathTrackingMode controls path tracking overhead.
const ( PathTrackingOff PathTrackingMode = iota PathTrackingErrorsOnly PathTrackingFull )
type ScannerHooks ¶ added in v0.9.0
type ScannerHooks interface {
SkipWhitespace(data []byte, pos int) int
FindQuoteOrEscape(data []byte, pos int) (quotePos int, escapePos int)
FindStructural(data []byte, pos int) int
}
ScannerHooks contains block-scan hooks for decoder whitespace and token scans.
type SegmentKind ¶ added in v0.9.0
type SegmentKind int
SegmentKind identifies path segment type.
const ( SegmentField SegmentKind = iota SegmentIndex )
type UnknownFieldPolicy ¶ added in v0.9.0
type UnknownFieldPolicy int
UnknownFieldPolicy controls unknown key handling.
const ( IgnoreUnknown UnknownFieldPolicy = iota ErrorOnUnknown )
type UnmarshalInterceptor ¶ added in v0.9.0
type UnmarshalInterceptors ¶ added in v0.9.0
type UnmarshalInterceptors map[string]UnmarshalInterceptor
type UnmarshalSession ¶ added in v0.9.0
type UnmarshalSession struct {
Options Options
Interceptors UnmarshalInterceptors
// contains filtered or unexported fields
}
func NewUnmarshalSession ¶ added in v0.9.0
func NewUnmarshalSession(options Options) *UnmarshalSession
func (*UnmarshalSession) PathRef ¶ added in v0.9.0
func (s *UnmarshalSession) PathRef() PathRef
func (*UnmarshalSession) PopPath ¶ added in v0.9.0
func (s *UnmarshalSession) PopPath()
func (*UnmarshalSession) PushField ¶ added in v0.9.0
func (s *UnmarshalSession) PushField(name string)
func (*UnmarshalSession) PushIndex ¶ added in v0.9.0
func (s *UnmarshalSession) PushIndex(index int)
type UnmarshalerArray ¶ added in v0.9.0
UnmarshalerArray receives array elements.
type UnmarshalerJSONArray ¶ added in v0.9.0
UnmarshalerJSONArray receives array elements.