jsonserialization

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 15 Imported by: 46

README

Kiota Json Serialization Library for Go

Go Serialization Text

The Json Serialization Library for Go is the Go JSON serialization library implementation.

A Kiota generated project will need a reference to a json serialization package to handle json payloads from an API endpoint.

Read more about Kiota here.

Using the Kiota Json Serialization Library

    go get github.com/microsoft/kiota-serialization-json-go

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Documentation

Overview

Package jsonserialization is the default Kiota serialization implementation for JSON. It relies on the standard Go JSON library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal added in v0.9.0

func Marshal(v absser.Parsable) ([]byte, error)

Marshal JSON-encodes a Parsable value. To enable dirty tracking and better performance, set the DefaultSerializationWriterFactoryInstance for "application/json".

func Unmarshal added in v0.9.0

func Unmarshal[T absser.Parsable](data []byte, model *T, parser absser.ParsableFactory) error

Unmarshal parses JSON-encoded data using a ParsableFactory and stores it in the value pointed to by model. To enable dirty tracking and better performance, set the DefaultParseNodeFactoryInstance for "application/json".

Types

type JsonParseNode

type JsonParseNode struct {
	// contains filtered or unexported fields
}

JsonParseNode is a ParseNode implementation for JSON.

func NewJsonParseNode

func NewJsonParseNode(content []byte) (*JsonParseNode, error)

NewJsonParseNode creates a new JsonParseNode.

func (*JsonParseNode) GetBoolValue

func (n *JsonParseNode) GetBoolValue() (*bool, error)

GetBoolValue returns a Bool value from the nodes.

func (*JsonParseNode) GetByteArrayValue

func (n *JsonParseNode) GetByteArrayValue() ([]byte, error)

GetByteArrayValue returns a ByteArray value from the nodes.

func (*JsonParseNode) GetByteValue

func (n *JsonParseNode) GetByteValue() (*byte, error)

GetBoolValue returns a Bool value from the nodes.

func (*JsonParseNode) GetChildNode

func (n *JsonParseNode) GetChildNode(index string) (absser.ParseNode, error)

GetChildNode returns a new parse node for the given identifier.

func (*JsonParseNode) GetCollectionOfEnumValues

func (n *JsonParseNode) GetCollectionOfEnumValues(parser absser.EnumFactory) ([]interface{}, error)

GetCollectionOfEnumValues returns the collection of Enum values from the node.

func (*JsonParseNode) GetCollectionOfObjectValues

func (n *JsonParseNode) GetCollectionOfObjectValues(ctor absser.ParsableFactory) ([]absser.Parsable, error)

GetCollectionOfObjectValues returns the collection of Parsable values from the node.

func (*JsonParseNode) GetCollectionOfPrimitiveValues

func (n *JsonParseNode) GetCollectionOfPrimitiveValues(targetType string) ([]interface{}, error)

GetCollectionOfPrimitiveValues returns the collection of primitive values from the node.

func (*JsonParseNode) GetDateOnlyValue

func (n *JsonParseNode) GetDateOnlyValue() (*absser.DateOnly, error)

GetDateOnlyValue returns a DateOnly value from the nodes.

func (*JsonParseNode) GetEnumValue

func (n *JsonParseNode) GetEnumValue(parser absser.EnumFactory) (interface{}, error)

GetEnumValue returns a Enum value from the nodes.

func (*JsonParseNode) GetFloat32Value

func (n *JsonParseNode) GetFloat32Value() (*float32, error)

GetFloat32Value returns a Float32 value from the nodes.

func (*JsonParseNode) GetFloat64Value

func (n *JsonParseNode) GetFloat64Value() (*float64, error)

GetFloat64Value returns a Float64 value from the nodes.

func (*JsonParseNode) GetISODurationValue

func (n *JsonParseNode) GetISODurationValue() (*absser.ISODuration, error)

GetISODurationValue returns a ISODuration value from the nodes.

func (*JsonParseNode) GetInt32Value

func (n *JsonParseNode) GetInt32Value() (*int32, error)

GetInt32Value returns a Int32 value from the nodes.

func (*JsonParseNode) GetInt64Value

func (n *JsonParseNode) GetInt64Value() (*int64, error)

GetInt64Value returns a Int64 value from the nodes.

func (*JsonParseNode) GetInt8Value

func (n *JsonParseNode) GetInt8Value() (*int8, error)

GetInt8Value returns a int8 value from the nodes.

func (*JsonParseNode) GetObjectValue

func (n *JsonParseNode) GetObjectValue(ctor absser.ParsableFactory) (absser.Parsable, error)

GetObjectValue returns the Parsable value from the node.

func (*JsonParseNode) GetOnAfterAssignFieldValues added in v0.8.0

func (n *JsonParseNode) GetOnAfterAssignFieldValues() absser.ParsableAction

func (*JsonParseNode) GetOnBeforeAssignFieldValues added in v0.8.0

func (n *JsonParseNode) GetOnBeforeAssignFieldValues() absser.ParsableAction

func (*JsonParseNode) GetRawValue added in v0.7.0

func (n *JsonParseNode) GetRawValue() (interface{}, error)

GetRawValue returns a ByteArray value from the nodes.

func (*JsonParseNode) GetStringValue

func (n *JsonParseNode) GetStringValue() (*string, error)

GetStringValue returns a String value from the nodes.

func (*JsonParseNode) GetTimeOnlyValue

func (n *JsonParseNode) GetTimeOnlyValue() (*absser.TimeOnly, error)

GetTimeOnlyValue returns a TimeOnly value from the nodes.

func (*JsonParseNode) GetTimeValue

func (n *JsonParseNode) GetTimeValue() (*time.Time, error)

GetTimeValue returns a Time value from the nodes.

func (*JsonParseNode) GetUUIDValue

func (n *JsonParseNode) GetUUIDValue() (*uuid.UUID, error)

GetUUIDValue returns a UUID value from the nodes.

func (*JsonParseNode) SetOnAfterAssignFieldValues added in v0.8.0

func (n *JsonParseNode) SetOnAfterAssignFieldValues(action absser.ParsableAction) error

func (*JsonParseNode) SetOnBeforeAssignFieldValues added in v0.8.0

func (n *JsonParseNode) SetOnBeforeAssignFieldValues(action absser.ParsableAction) error

func (*JsonParseNode) SetValue

func (n *JsonParseNode) SetValue(value interface{})

SetValue is obsolete, parse nodes are not meant to be settable externally

type JsonParseNodeFactory

type JsonParseNodeFactory struct {
}

JsonParseNodeFactory is a ParseNodeFactory implementation for JSON

func NewJsonParseNodeFactory

func NewJsonParseNodeFactory() *JsonParseNodeFactory

NewJsonParseNodeFactory creates a new JsonParseNodeFactory

func (*JsonParseNodeFactory) GetRootParseNode

func (f *JsonParseNodeFactory) GetRootParseNode(contentType string, content []byte) (absser.ParseNode, error)

GetRootParseNode return a new ParseNode instance that is the root of the content

func (*JsonParseNodeFactory) GetValidContentType

func (f *JsonParseNodeFactory) GetValidContentType() (string, error)

GetValidContentType returns the content type this factory's parse nodes can deserialize.

type JsonSerializationWriter

type JsonSerializationWriter struct {
	// contains filtered or unexported fields
}

JsonSerializationWriter implements SerializationWriter for JSON.

func NewJsonSerializationWriter

func NewJsonSerializationWriter() *JsonSerializationWriter

NewJsonSerializationWriter creates a new instance of the JsonSerializationWriter.

func (*JsonSerializationWriter) Close

func (w *JsonSerializationWriter) Close() error

Close relases the internal buffer. Subsequent calls to the writer will panic.

func (*JsonSerializationWriter) GetOnAfterObjectSerialization added in v0.8.0

func (w *JsonSerializationWriter) GetOnAfterObjectSerialization() absser.ParsableAction

func (*JsonSerializationWriter) GetOnBeforeSerialization added in v0.8.0

func (w *JsonSerializationWriter) GetOnBeforeSerialization() absser.ParsableAction

func (*JsonSerializationWriter) GetOnStartObjectSerialization added in v0.8.0

func (w *JsonSerializationWriter) GetOnStartObjectSerialization() absser.ParsableWriter

func (*JsonSerializationWriter) GetSerializedContent

func (w *JsonSerializationWriter) GetSerializedContent() ([]byte, error)

GetSerializedContent returns the resulting byte array from the serialization writer.

func (*JsonSerializationWriter) Reset added in v0.9.3

func (w *JsonSerializationWriter) Reset() error

Reset sets the internal buffer to empty, allowing the writer to be reused.

func (*JsonSerializationWriter) SetOnAfterObjectSerialization added in v0.8.0

func (w *JsonSerializationWriter) SetOnAfterObjectSerialization(action absser.ParsableAction) error

func (*JsonSerializationWriter) SetOnBeforeSerialization added in v0.8.0

func (w *JsonSerializationWriter) SetOnBeforeSerialization(action absser.ParsableAction) error

func (*JsonSerializationWriter) SetOnStartObjectSerialization added in v0.8.0

func (w *JsonSerializationWriter) SetOnStartObjectSerialization(writer absser.ParsableWriter) error

func (*JsonSerializationWriter) WriteAdditionalData

func (w *JsonSerializationWriter) WriteAdditionalData(value map[string]interface{}) error

WriteAdditionalData writes additional data to underlying the byte array.

func (*JsonSerializationWriter) WriteAnyValue added in v0.7.1

func (w *JsonSerializationWriter) WriteAnyValue(key string, value interface{}) error

WriteAnyValue an unknown value as a parameter.

func (*JsonSerializationWriter) WriteBoolValue

func (w *JsonSerializationWriter) WriteBoolValue(key string, value *bool) error

WriteBoolValue writes a Bool value to underlying the byte array.

func (*JsonSerializationWriter) WriteByteArrayValue

func (w *JsonSerializationWriter) WriteByteArrayValue(key string, value []byte) error

WriteByteArrayValue writes a ByteArray value to underlying the byte array.

func (*JsonSerializationWriter) WriteByteValue

func (w *JsonSerializationWriter) WriteByteValue(key string, value *byte) error

WriteByteValue writes a Byte value to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfBoolValues

func (w *JsonSerializationWriter) WriteCollectionOfBoolValues(key string, collection []bool) error

WriteCollectionOfBoolValues writes a collection of Bool values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfByteValues

func (w *JsonSerializationWriter) WriteCollectionOfByteValues(key string, collection []byte) error

WriteCollectionOfByteValues writes a collection of Byte values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfDateOnlyValues

func (w *JsonSerializationWriter) WriteCollectionOfDateOnlyValues(key string, collection []absser.DateOnly) error

WriteCollectionOfDateOnlyValues writes a collection of DateOnly values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfFloat32Values

func (w *JsonSerializationWriter) WriteCollectionOfFloat32Values(key string, collection []float32) error

WriteCollectionOfFloat32Values writes a collection of Float32 values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfFloat64Values

func (w *JsonSerializationWriter) WriteCollectionOfFloat64Values(key string, collection []float64) error

WriteCollectionOfFloat64Values writes a collection of Float64 values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfISODurationValues

func (w *JsonSerializationWriter) WriteCollectionOfISODurationValues(key string, collection []absser.ISODuration) error

WriteCollectionOfISODurationValues writes a collection of ISODuration values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfInt32Values

func (w *JsonSerializationWriter) WriteCollectionOfInt32Values(key string, collection []int32) error

WriteCollectionOfInt32Values writes a collection of Int32 values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfInt64Values

func (w *JsonSerializationWriter) WriteCollectionOfInt64Values(key string, collection []int64) error

WriteCollectionOfInt64Values writes a collection of Int64 values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfInt8Values

func (w *JsonSerializationWriter) WriteCollectionOfInt8Values(key string, collection []int8) error

WriteCollectionOfInt8Values writes a collection of int8 values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfObjectValues

func (w *JsonSerializationWriter) WriteCollectionOfObjectValues(key string, collection []absser.Parsable) error

WriteCollectionOfObjectValues writes a collection of Parsable values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfStringValues

func (w *JsonSerializationWriter) WriteCollectionOfStringValues(key string, collection []string) error

WriteCollectionOfStringValues writes a collection of String values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfTimeOnlyValues

func (w *JsonSerializationWriter) WriteCollectionOfTimeOnlyValues(key string, collection []absser.TimeOnly) error

WriteCollectionOfTimeOnlyValues writes a collection of TimeOnly values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfTimeValues

func (w *JsonSerializationWriter) WriteCollectionOfTimeValues(key string, collection []time.Time) error

WriteCollectionOfTimeValues writes a collection of Time values to underlying the byte array.

func (*JsonSerializationWriter) WriteCollectionOfUUIDValues

func (w *JsonSerializationWriter) WriteCollectionOfUUIDValues(key string, collection []uuid.UUID) error

WriteCollectionOfUUIDValues writes a collection of UUID values to underlying the byte array.

func (*JsonSerializationWriter) WriteDateOnlyValue

func (w *JsonSerializationWriter) WriteDateOnlyValue(key string, value *absser.DateOnly) error

WriteDateOnlyValue writes a DateOnly value to underlying the byte array.

func (*JsonSerializationWriter) WriteFloat32Value

func (w *JsonSerializationWriter) WriteFloat32Value(key string, value *float32) error

WriteFloat32Value writes a Float32 value to underlying the byte array.

func (*JsonSerializationWriter) WriteFloat64Value

func (w *JsonSerializationWriter) WriteFloat64Value(key string, value *float64) error

WriteFloat64Value writes a Float64 value to underlying the byte array.

func (*JsonSerializationWriter) WriteISODurationValue

func (w *JsonSerializationWriter) WriteISODurationValue(key string, value *absser.ISODuration) error

WriteISODurationValue writes a ISODuration value to underlying the byte array.

func (*JsonSerializationWriter) WriteInt32Value

func (w *JsonSerializationWriter) WriteInt32Value(key string, value *int32) error

WriteInt32Value writes a Int32 value to underlying the byte array.

func (*JsonSerializationWriter) WriteInt64Value

func (w *JsonSerializationWriter) WriteInt64Value(key string, value *int64) error

WriteInt64Value writes a Int64 value to underlying the byte array.

func (*JsonSerializationWriter) WriteInt8Value

func (w *JsonSerializationWriter) WriteInt8Value(key string, value *int8) error

WriteInt8Value writes a int8 value to underlying the byte array.

func (*JsonSerializationWriter) WriteNullValue added in v0.8.0

func (w *JsonSerializationWriter) WriteNullValue(key string) error

func (*JsonSerializationWriter) WriteObjectValue

func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsable, additionalValuesToMerge ...absser.Parsable) error

WriteObjectValue writes a Parsable value to underlying the byte array.

func (*JsonSerializationWriter) WriteStringValue

func (w *JsonSerializationWriter) WriteStringValue(key string, value *string) error

WriteStringValue writes a String value to underlying the byte array.

func (*JsonSerializationWriter) WriteTimeOnlyValue

func (w *JsonSerializationWriter) WriteTimeOnlyValue(key string, value *absser.TimeOnly) error

WriteTimeOnlyValue writes a TimeOnly value to underlying the byte array.

func (*JsonSerializationWriter) WriteTimeValue

func (w *JsonSerializationWriter) WriteTimeValue(key string, value *time.Time) error

WriteTimeValue writes a Time value to underlying the byte array.

func (*JsonSerializationWriter) WriteUUIDValue

func (w *JsonSerializationWriter) WriteUUIDValue(key string, value *uuid.UUID) error

WriteUUIDValue writes a UUID value to underlying the byte array.

type JsonSerializationWriterFactory

type JsonSerializationWriterFactory struct {
}

JsonSerializationWriterFactory implements SerializationWriterFactory for JSON.

func NewJsonSerializationWriterFactory

func NewJsonSerializationWriterFactory() *JsonSerializationWriterFactory

NewJsonSerializationWriterFactory creates a new instance of the JsonSerializationWriterFactory.

func (*JsonSerializationWriterFactory) GetSerializationWriter

func (f *JsonSerializationWriterFactory) GetSerializationWriter(contentType string) (absser.SerializationWriter, error)

GetSerializationWriter returns the relevant SerializationWriter instance for the given content type

func (*JsonSerializationWriterFactory) GetValidContentType

func (f *JsonSerializationWriterFactory) GetValidContentType() (string, error)

GetValidContentType returns the valid content type for the SerializationWriterFactoryRegistry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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