Documentation ¶
Overview ¶
Package jsoninfo provides information and functions for marshalling/unmarshalling JSON.
Index ¶
- func MarshalRef(value string, otherwise interface{}) ([]byte, error)
- func MarshalStrictStruct(value StrictStruct) ([]byte, error)
- func NewUnsupportedPropertiesError(v interface{}, m map[string]json.RawMessage) error
- func UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error
- func UnmarshalStrictStruct(data []byte, value StrictStruct) error
- type FieldInfo
- type ObjectDecoder
- type ObjectEncoder
- func (encoder *ObjectEncoder) Bytes() ([]byte, error)
- func (encoder *ObjectEncoder) EncodeExtension(key string, value interface{}) error
- func (encoder *ObjectEncoder) EncodeExtensionMap(value map[string]json.RawMessage) error
- func (encoder *ObjectEncoder) EncodeStructFieldsAndExtensions(value interface{}) error
- type StrictStruct
- type TypeInfo
- type UnsupportedPropertiesError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalRef ¶
func MarshalStrictStruct ¶
func MarshalStrictStruct(value StrictStruct) ([]byte, error)
MarshalStrictStruct function:
- Marshals struct fields, ignoring MarshalJSON() and fields without 'json' tag.
- Correctly handles StrictStruct semantics.
func NewUnsupportedPropertiesError ¶
func NewUnsupportedPropertiesError(v interface{}, m map[string]json.RawMessage) error
func UnmarshalRef ¶
func UnmarshalStrictStruct ¶
func UnmarshalStrictStruct(data []byte, value StrictStruct) error
UnmarshalStrictStruct function:
- Unmarshals struct fields, ignoring UnmarshalJSON(...) and fields without 'json' tag.
- Correctly handles StrictStruct
Types ¶
type FieldInfo ¶
type FieldInfo struct { MultipleFields bool // Whether multiple Go fields share this JSON name HasJSONTag bool TypeIsMarshaller bool TypeIsUnmarshaller bool JSONOmitEmpty bool JSONString bool Index []int Type reflect.Type JSONName string }
FieldInfo contains information about JSON serialization of a field.
type ObjectDecoder ¶
type ObjectDecoder struct { Data []byte // contains filtered or unexported fields }
func NewObjectDecoder ¶
func NewObjectDecoder(data []byte) (*ObjectDecoder, error)
func (*ObjectDecoder) DecodeExtensionMap ¶
func (decoder *ObjectDecoder) DecodeExtensionMap() map[string]json.RawMessage
DecodeExtensionMap returns all properties that were not decoded previously.
func (*ObjectDecoder) DecodeStructFieldsAndExtensions ¶
func (decoder *ObjectDecoder) DecodeStructFieldsAndExtensions(value interface{}) error
type ObjectEncoder ¶
type ObjectEncoder struct {
// contains filtered or unexported fields
}
func NewObjectEncoder ¶
func NewObjectEncoder() *ObjectEncoder
func (*ObjectEncoder) Bytes ¶
func (encoder *ObjectEncoder) Bytes() ([]byte, error)
Bytes returns the result of encoding.
func (*ObjectEncoder) EncodeExtension ¶
func (encoder *ObjectEncoder) EncodeExtension(key string, value interface{}) error
EncodeExtension adds a key/value to the current JSON object.
func (*ObjectEncoder) EncodeExtensionMap ¶
func (encoder *ObjectEncoder) EncodeExtensionMap(value map[string]json.RawMessage) error
EncodeExtensionMap adds all properties to the result.
func (*ObjectEncoder) EncodeStructFieldsAndExtensions ¶
func (encoder *ObjectEncoder) EncodeStructFieldsAndExtensions(value interface{}) error
type StrictStruct ¶
type StrictStruct interface { EncodeWith(encoder *ObjectEncoder, value interface{}) error DecodeWith(decoder *ObjectDecoder, value interface{}) error }
type TypeInfo ¶
TypeInfo contains information about JSON serialization of a type
func GetTypeInfo ¶
GetTypeInfo returns TypeInfo for the given type.
func GetTypeInfoForValue ¶
func GetTypeInfoForValue(value interface{}) *TypeInfo
func (*TypeInfo) FieldNames ¶
FieldNames returns all field names
type UnsupportedPropertiesError ¶
type UnsupportedPropertiesError struct { Value interface{} UnsupportedProperties map[string]json.RawMessage }
UnsupportedPropertiesError is a helper for extensions that want to refuse unsupported JSON object properties.
It produces a helpful error message.
func (*UnsupportedPropertiesError) Error ¶
func (err *UnsupportedPropertiesError) Error() string