Documentation
¶
Overview ¶
Package jsonx is a mvm-aware replacement for the encoding/json functions that need to honour mvm-defined methods on struct types (MarshalJSON, UnmarshalJSON). It walks mvm *vm.Type metadata to traverse struct fields and dispatches mvm methods via Machine.CallFunc. Values whose mvm type is unknown are forwarded to the native encoding/json implementation.
Dispatch is wired through vm.RegisterArgProxy / RegisterArgProxyMethod: mvm Iface arguments to json.Marshal / Unmarshal / MarshalIndent and to (*Encoder).Encode / (*Decoder).Decode are wrapped as marshalProxy / unmarshalProxy pointers whose MarshalJSON / UnmarshalJSON methods re-enter the walker. Native encoding/json reflection sees the proxies as ordinary json.Marshaler / json.Unmarshaler implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is the mvm-aware replacement for *encoding/json.Decoder. It wraps a native *json.Decoder; when mvm calls Decode, the argument arrives as a *unmarshalProxy that satisfies json.Unmarshaler, so native decoding drives UnmarshalJSON back into the walker.
func NewDecoder ¶
NewDecoder returns a new jsonx.Decoder that reads from r.
func (*Decoder) DisallowUnknownFields ¶
func (d *Decoder) DisallowUnknownFields()
DisallowUnknownFields forwards to (*json.Decoder).DisallowUnknownFields.
func (*Decoder) InputOffset ¶
InputOffset forwards to (*json.Decoder).InputOffset.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is the mvm-aware replacement for *encoding/json.Encoder. Mvm resolves json.Encoder to this type via patchEncodingJSON, so user code that spells *json.Encoder actually gets *jsonx.Encoder. When mvm calls Encode with an Iface argument, vm.bridgeArgs wraps it as a *marshalProxy whose MarshalJSON re-enters the jsonx walker.
func NewEncoder ¶
NewEncoder returns a new jsonx.Encoder that writes to w, matching the signature of encoding/json.NewEncoder.
func (*Encoder) Encode ¶
Encode serialises v as JSON and writes a newline-terminated line. Mvm callers receive v as a *marshalProxy (installed by vm.RegisterArgProxyMethod); native json.Marshal finds its MarshalJSON and recurses back into the walker.
func (*Encoder) SetEscapeHTML ¶
SetEscapeHTML matches the (*json.Encoder) method set for API compatibility. The flag is accepted but unused.