serialization

package
v0.0.0-...-62d34d7 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(in interface{}) (string, error)

Converts a struct into a json string. If input is a string and not a struct no conversion will take place and string is returned instead

Types

type MockItem

type MockItem struct {
	MockString string
}

func (MockItem) ToStruct

func (mockItem MockItem) ToStruct(jsonString string) (interface{}, error)

ToStruct converts json string to struct

type NestedMockItem

type NestedMockItem struct {
	NestedItem MockItem
}

func (NestedMockItem) ToStruct

func (mockItem NestedMockItem) ToStruct(jsonString string) (interface{}, error)

ToStruct converts json string to struct

type Serializable

type Serializable interface {
	ToStruct(jsonString string) (interface{}, error)
}

Serializable converts a json string into the struct

Example: For the struct

type Person struct {
	Name string
}

The ToStruct function looks like:

func (person *Person) ToStruct(jsonString string) (interface{}, error) {
	err := json.Unmarshal([]byte(jsonString), &person)
	return person, err
}

Jump to

Keyboard shortcuts

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