package jsoninfo

import "github.com/getkin/kin-openapi/jsoninfo"

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

Index

Functions

func MarshalRef

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

func MarshalStrictStruct

func MarshalStrictStruct(value StrictStruct) ([]byte, error)

MarshalStrictStruct function:

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:

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

Source Files

doc.go field_info.go marshal.go marshal_ref.go strict_struct.go type_info.go unmarshal.go unsupported_properties_error.go

Version
v0.32.0
Published
Nov 25, 2020
Platform
linux/amd64
Imports
8 packages
Last checked
1 second ago

Tools for package owners.