mfj

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 License: MIT Imports: 6 Imported by: 1

README

json (mfjson)

The mfjson package provides marshal/unmarshal for objects containing interface fields
mfjson generates <file>.mfjson.go file. The file contains proxy structs for marshaling struct.

Attributes

//mfjson:interface some_name - Marks struct for add to generator with name some_name

//mfjson:add //easyjson:json - Add additional comment to proxy class

//mfjson:marshal - Mark struct as marshable with mfjson

mfjson:"true" - Marks fiels as interfacable. The field will marshal with generator

Usage

Run code gen
# install
go get -u github.com/myfantasy/json/
go install github.com/myfantasy/json/mfjson

# run
mfjson <file>.go
Code

Example for generate:


type TestInt1 interface {
	BlaName() string
}

// Generate registaration struct in generator
//mfjson:interface b_test_struct
type B struct {
	A string
	B float64
}

func (b *B) BlaName() string {
	return "B_BlaName"
}

//mfjson:add //easyjson:json
//mfjson:marshal
type Example struct {
	A int `json:"id"`
	B int64
	C TestInt1                    `json:"c" mfjson:"true"`
}

//mfjson:marshal
type AasList []TestInt1

//mfjson:add //easyjson:json
//mfjson:marshal
type AasMap map[string]TestInt1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalStructFactory = &StructFactory{
	Generators:    map[string]JsonUnmarshalObjectGenerate{},
	GeneratorsNil: map[string]JsonUnmarshalObjectGenerate{},
}

Functions

func MarshalIndentMust

func MarshalIndentMust(v interface{}, prefix, indent string) string

Types

type IStructView

type IStructView struct {
	Type string          `json:"_type"`
	Data json.RawMessage `json:"data"`
}

func (IStructView) MarshalEasyJSON

func (v IStructView) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (IStructView) MarshalJSON

func (v IStructView) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*IStructView) UnmarshalEasyJSON

func (v *IStructView) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*IStructView) UnmarshalJSON

func (v *IStructView) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type JsonInterfaceMarshaller

type JsonInterfaceMarshaller interface {
	UnmarshalJSONTypeName() string
}

type JsonUnmarshalObjectGenerate

type JsonUnmarshalObjectGenerate func() JsonInterfaceMarshaller

type StructFactory

type StructFactory struct {
	Generators    map[string]JsonUnmarshalObjectGenerate
	GeneratorsNil map[string]JsonUnmarshalObjectGenerate
	// contains filtered or unexported fields
}

StructFactory generate structs for json unmarshal

func (*StructFactory) Add

func (jsf *StructFactory) Add(name string, generator JsonUnmarshalObjectGenerate)

func (*StructFactory) AddNil

func (jsf *StructFactory) AddNil(name string, generator JsonUnmarshalObjectGenerate)

func (*StructFactory) Get

func (jsf *StructFactory) Get(name string) (obj interface{}, err *mft.Error)

func (*StructFactory) GetNil

func (jsf *StructFactory) GetNil(name string) (obj interface{}, err *mft.Error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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