Skip to content

Commit

Permalink
- adds doc comments and json shorthands
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Nov 1, 2023
1 parent 56b3c5e commit 6be9498
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions serialization/kiota_json_serializer.go
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 6 additions & 0 deletions serialization/kiota_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6be9498

Please sign in to comment.