Documentation
¶
Index ¶
- func MarshalMarshalerTo[T json.MarshalerTo](v T) ([]byte, error)
- func WriteField[T json.MarshalerTo](e *jsontext.Encoder, name string, v T) error
- func WriteFieldArray[T json.MarshalerTo](e *jsontext.Encoder, name string, items []T) error
- func WriteFieldValue(e *jsontext.Encoder, name string, v any) error
- func WriteMarshalerToArray[T json.MarshalerTo](e *jsontext.Encoder, items []T) error
- func WriteMarshalerToArrayOrNull[T json.MarshalerTo](e *jsontext.Encoder, items []T) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalMarshalerTo ¶
func MarshalMarshalerTo[T json.MarshalerTo](v T) ([]byte, error)
MarshalMarshalerTo provides a MarshalJSON implementation for any type that implements json.MarshalerTo. json.Marshal dispatches to MarshalJSONTo, so this doesn't recurse; the constraint is what guarantees that at compile time.
This is the entry point into v2 that establishes v1 options, per the package-level comment above.
func WriteField ¶
WriteField writes the object member name and then v's JSON encoding, so that the member is written and checked in one statement. A nil v is written as JSON null rather than dispatched to MarshalJSONTo: v1's reflection-based encoder already does this for a nil pointer, so writing null here keeps output identical to v1, rather than panicking on the types whose MarshalJSONTo assumes a non-nil receiver.
func WriteFieldArray ¶
WriteFieldArray writes the object member name and then the JSON array of items.
func WriteFieldValue ¶
WriteFieldValue is WriteField for values that don't implement json.MarshalerTo.
func WriteMarshalerToArray ¶
func WriteMarshalerToArray[T json.MarshalerTo](e *jsontext.Encoder, items []T) error
WriteMarshalerToArray writes the JSON array of items to the encoder.
func WriteMarshalerToArrayOrNull ¶
func WriteMarshalerToArrayOrNull[T json.MarshalerTo](e *jsontext.Encoder, items []T) error
WriteMarshalerToArrayOrNull is WriteMarshalerToArray but writes null for a nil slice, as encoding/json v1 does. Types whose pre-1.27 MarshalJSON returns "[]" for an empty value must keep using WriteMarshalerToArray.
Types ¶
This section is empty.