From 6be9498af91231b5369f5c2a2c37d8cb3a2fe84c Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 1 Nov 2023 14:30:28 -0400 Subject: [PATCH] - adds doc comments and json shorthands --- serialization/kiota_json_serializer.go | 23 +++++++++++++++++++++++ serialization/kiota_serializer.go | 6 ++++++ 2 files changed, 29 insertions(+) create mode 100644 serialization/kiota_json_serializer.go diff --git a/serialization/kiota_json_serializer.go b/serialization/kiota_json_serializer.go new file mode 100644 index 0000000..80aa59e --- /dev/null +++ b/serialization/kiota_json_serializer.go @@ -0,0 +1,23 @@ +package serialization + +var jsonContentType = "application/json" + +// SerializeToJson serializes the given model to JSON +func SerializeToJson(model Parsable) ([]byte, error) { + return Serialize(jsonContentType, model) +} + +// SerializeCollectionToJson serializes the given models to JSON +func SerializeCollectionToJson(models []Parsable) ([]byte, error) { + return SerializeCollection(jsonContentType, models) +} + +// DeserializeFromJson deserializes the given JSON to a model +func DeserializeFromJson(content []byte, parsableFactory ParsableFactory) (Parsable, error) { + return Deserialize(jsonContentType, content, parsableFactory) +} + +// DeserializeCollectionFromJson deserializes the given JSON to a collection of models +func DeserializeCollectionFromJson(content []byte, parsableFactory ParsableFactory) ([]Parsable, error) { + return DeserializeCollection(jsonContentType, content, parsableFactory) +} diff --git a/serialization/kiota_serializer.go b/serialization/kiota_serializer.go index 64ac43a..7cc44c6 100644 --- a/serialization/kiota_serializer.go +++ b/serialization/kiota_serializer.go @@ -4,6 +4,7 @@ import ( "errors" ) +// Serialize serializes the given model into a byte array. func Serialize(contentType string, model Parsable) ([]byte, error) { writer, err := getSerializationWriter(contentType, model) if err != nil { @@ -16,6 +17,8 @@ func Serialize(contentType string, model Parsable) ([]byte, error) { } return writer.GetSerializedContent() } + +// SerializeCollection serializes the given models into a byte array. func SerializeCollection(contentType string, models []Parsable) ([]byte, error) { writer, err := getSerializationWriter(contentType, models) if err != nil { @@ -42,6 +45,7 @@ func getSerializationWriter(contentType string, value interface{}) (Serializatio return writer, nil } +// Deserialize deserializes the given byte array into a model. func Deserialize(contentType string, content []byte, parsableFactory ParsableFactory) (Parsable, error) { node, err := getParseNode(contentType, content, parsableFactory) if err != nil { @@ -69,6 +73,8 @@ func getParseNode(contentType string, content []byte, parsableFactory ParsableFa } return node, nil } + +// DeserializeCollection deserializes the given byte array into a collection of models. func DeserializeCollection(contentType string, content []byte, parsableFactory ParsableFactory) ([]Parsable, error) { node, err := getParseNode(contentType, content, parsableFactory) if err != nil {