jsoninfo

package
v0.105.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package jsoninfo provides information and functions for marshalling/unmarshalling JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalRef

func MarshalRef(value string, otherwise interface{}) ([]byte, error)

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 UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error

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.

func AppendFields

func AppendFields(fields []FieldInfo, parentIndex []int, t reflect.Type) []FieldInfo

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

type TypeInfo struct {
	Type   reflect.Type
	Fields []FieldInfo
}

TypeInfo contains information about JSON serialization of a type

func GetTypeInfo

func GetTypeInfo(t reflect.Type) *TypeInfo

GetTypeInfo returns TypeInfo for the given type.

func GetTypeInfoForValue

func GetTypeInfoForValue(value interface{}) *TypeInfo

func (*TypeInfo) FieldNames

func (typeInfo *TypeInfo) FieldNames() []string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL