...

Source file src/github.com/mailru/easyjson/tests/data.go

Documentation: github.com/mailru/easyjson/tests

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  	"net"
     7  	"time"
     8  
     9  	"github.com/mailru/easyjson"
    10  	"github.com/mailru/easyjson/opt"
    11  )
    12  
    13  type PrimitiveTypes struct {
    14  	String string
    15  	Bool   bool
    16  
    17  	Int   int
    18  	Int8  int8
    19  	Int16 int16
    20  	Int32 int32
    21  	Int64 int64
    22  
    23  	Uint   uint
    24  	Uint8  uint8
    25  	Uint16 uint16
    26  	Uint32 uint32
    27  	Uint64 uint64
    28  
    29  	IntString   int   `json:",string"`
    30  	Int8String  int8  `json:",string"`
    31  	Int16String int16 `json:",string"`
    32  	Int32String int32 `json:",string"`
    33  	Int64String int64 `json:",string"`
    34  
    35  	UintString   uint   `json:",string"`
    36  	Uint8String  uint8  `json:",string"`
    37  	Uint16String uint16 `json:",string"`
    38  	Uint32String uint32 `json:",string"`
    39  	Uint64String uint64 `json:",string"`
    40  
    41  	Float32 float32
    42  	Float64 float64
    43  
    44  	Float32String float32 `json:",string"`
    45  	Float64String float64 `json:",string"`
    46  
    47  	Ptr    *string
    48  	PtrNil *string
    49  }
    50  
    51  var str = "bla"
    52  
    53  var primitiveTypesValue = PrimitiveTypes{
    54  	String: "test", Bool: true,
    55  
    56  	Int:   math.MinInt32,
    57  	Int8:  math.MinInt8,
    58  	Int16: math.MinInt16,
    59  	Int32: math.MinInt32,
    60  	Int64: math.MinInt64,
    61  
    62  	Uint:   math.MaxUint32,
    63  	Uint8:  math.MaxUint8,
    64  	Uint16: math.MaxUint16,
    65  	Uint32: math.MaxUint32,
    66  	Uint64: math.MaxUint64,
    67  
    68  	IntString:   math.MinInt32,
    69  	Int8String:  math.MinInt8,
    70  	Int16String: math.MinInt16,
    71  	Int32String: math.MinInt32,
    72  	Int64String: math.MinInt64,
    73  
    74  	UintString:   math.MaxUint32,
    75  	Uint8String:  math.MaxUint8,
    76  	Uint16String: math.MaxUint16,
    77  	Uint32String: math.MaxUint32,
    78  	Uint64String: math.MaxUint64,
    79  
    80  	Float32: 1.5,
    81  	Float64: math.MaxFloat64,
    82  
    83  	Float32String: 1.5,
    84  	Float64String: math.MaxFloat64,
    85  
    86  	Ptr: &str,
    87  }
    88  
    89  var primitiveTypesString = "{" +
    90  	`"String":"test","Bool":true,` +
    91  
    92  	`"Int":` + fmt.Sprint(math.MinInt32) + `,` +
    93  	`"Int8":` + fmt.Sprint(math.MinInt8) + `,` +
    94  	`"Int16":` + fmt.Sprint(math.MinInt16) + `,` +
    95  	`"Int32":` + fmt.Sprint(math.MinInt32) + `,` +
    96  	`"Int64":` + fmt.Sprint(int64(math.MinInt64)) + `,` +
    97  
    98  	`"Uint":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
    99  	`"Uint8":` + fmt.Sprint(math.MaxUint8) + `,` +
   100  	`"Uint16":` + fmt.Sprint(math.MaxUint16) + `,` +
   101  	`"Uint32":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
   102  	`"Uint64":` + fmt.Sprint(uint64(math.MaxUint64)) + `,` +
   103  
   104  	`"IntString":"` + fmt.Sprint(math.MinInt32) + `",` +
   105  	`"Int8String":"` + fmt.Sprint(math.MinInt8) + `",` +
   106  	`"Int16String":"` + fmt.Sprint(math.MinInt16) + `",` +
   107  	`"Int32String":"` + fmt.Sprint(math.MinInt32) + `",` +
   108  	`"Int64String":"` + fmt.Sprint(int64(math.MinInt64)) + `",` +
   109  
   110  	`"UintString":"` + fmt.Sprint(uint32(math.MaxUint32)) + `",` +
   111  	`"Uint8String":"` + fmt.Sprint(math.MaxUint8) + `",` +
   112  	`"Uint16String":"` + fmt.Sprint(math.MaxUint16) + `",` +
   113  	`"Uint32String":"` + fmt.Sprint(uint32(math.MaxUint32)) + `",` +
   114  	`"Uint64String":"` + fmt.Sprint(uint64(math.MaxUint64)) + `",` +
   115  
   116  	`"Float32":` + fmt.Sprint(1.5) + `,` +
   117  	`"Float64":` + fmt.Sprint(math.MaxFloat64) + `,` +
   118  
   119  	`"Float32String":"` + fmt.Sprint(1.5) + `",` +
   120  	`"Float64String":"` + fmt.Sprint(math.MaxFloat64) + `",` +
   121  
   122  	`"Ptr":"bla",` +
   123  	`"PtrNil":null` +
   124  
   125  	"}"
   126  
   127  type (
   128  	NamedString string
   129  	NamedBool   bool
   130  
   131  	NamedInt   int
   132  	NamedInt8  int8
   133  	NamedInt16 int16
   134  	NamedInt32 int32
   135  	NamedInt64 int64
   136  
   137  	NamedUint   uint
   138  	NamedUint8  uint8
   139  	NamedUint16 uint16
   140  	NamedUint32 uint32
   141  	NamedUint64 uint64
   142  
   143  	NamedFloat32 float32
   144  	NamedFloat64 float64
   145  
   146  	NamedStrPtr *string
   147  )
   148  
   149  type NamedPrimitiveTypes struct {
   150  	String NamedString
   151  	Bool   NamedBool
   152  
   153  	Int   NamedInt
   154  	Int8  NamedInt8
   155  	Int16 NamedInt16
   156  	Int32 NamedInt32
   157  	Int64 NamedInt64
   158  
   159  	Uint   NamedUint
   160  	Uint8  NamedUint8
   161  	Uint16 NamedUint16
   162  	Uint32 NamedUint32
   163  	Uint64 NamedUint64
   164  
   165  	Float32 NamedFloat32
   166  	Float64 NamedFloat64
   167  
   168  	Ptr    NamedStrPtr
   169  	PtrNil NamedStrPtr
   170  }
   171  
   172  var namedPrimitiveTypesValue = NamedPrimitiveTypes{
   173  	String: "test",
   174  	Bool:   true,
   175  
   176  	Int:   math.MinInt32,
   177  	Int8:  math.MinInt8,
   178  	Int16: math.MinInt16,
   179  	Int32: math.MinInt32,
   180  	Int64: math.MinInt64,
   181  
   182  	Uint:   math.MaxUint32,
   183  	Uint8:  math.MaxUint8,
   184  	Uint16: math.MaxUint16,
   185  	Uint32: math.MaxUint32,
   186  	Uint64: math.MaxUint64,
   187  
   188  	Float32: 1.5,
   189  	Float64: math.MaxFloat64,
   190  
   191  	Ptr: NamedStrPtr(&str),
   192  }
   193  
   194  var namedPrimitiveTypesString = "{" +
   195  	`"String":"test",` +
   196  	`"Bool":true,` +
   197  
   198  	`"Int":` + fmt.Sprint(math.MinInt32) + `,` +
   199  	`"Int8":` + fmt.Sprint(math.MinInt8) + `,` +
   200  	`"Int16":` + fmt.Sprint(math.MinInt16) + `,` +
   201  	`"Int32":` + fmt.Sprint(math.MinInt32) + `,` +
   202  	`"Int64":` + fmt.Sprint(int64(math.MinInt64)) + `,` +
   203  
   204  	`"Uint":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
   205  	`"Uint8":` + fmt.Sprint(math.MaxUint8) + `,` +
   206  	`"Uint16":` + fmt.Sprint(math.MaxUint16) + `,` +
   207  	`"Uint32":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
   208  	`"Uint64":` + fmt.Sprint(uint64(math.MaxUint64)) + `,` +
   209  
   210  	`"Float32":` + fmt.Sprint(1.5) + `,` +
   211  	`"Float64":` + fmt.Sprint(math.MaxFloat64) + `,` +
   212  
   213  	`"Ptr":"bla",` +
   214  	`"PtrNil":null` +
   215  	"}"
   216  
   217  type SubStruct struct {
   218  	Value     string
   219  	Value2    string
   220  	unexpored bool
   221  }
   222  
   223  type SubP struct {
   224  	V string
   225  }
   226  
   227  type SubStructAlias SubStruct
   228  
   229  type Structs struct {
   230  	SubStruct
   231  	*SubP
   232  
   233  	Value2 int
   234  
   235  	Sub1   SubStruct `json:"substruct"`
   236  	Sub2   *SubStruct
   237  	SubNil *SubStruct
   238  
   239  	SubSlice    []SubStruct
   240  	SubSliceNil []SubStruct
   241  
   242  	SubPtrSlice    []*SubStruct
   243  	SubPtrSliceNil []*SubStruct
   244  
   245  	SubA1 SubStructAlias
   246  	SubA2 *SubStructAlias
   247  
   248  	Anonymous struct {
   249  		V string
   250  		I int
   251  	}
   252  	Anonymous1 *struct {
   253  		V string
   254  	}
   255  
   256  	AnonymousSlice    []struct{ V int }
   257  	AnonymousPtrSlice []*struct{ V int }
   258  
   259  	Slice []string
   260  
   261  	unexported bool
   262  }
   263  
   264  var structsValue = Structs{
   265  	SubStruct: SubStruct{Value: "test"},
   266  	SubP:      &SubP{V: "subp"},
   267  
   268  	Value2: 5,
   269  
   270  	Sub1: SubStruct{Value: "test1", Value2: "v"},
   271  	Sub2: &SubStruct{Value: "test2", Value2: "v2"},
   272  
   273  	SubSlice: []SubStruct{
   274  		{Value: "s1"},
   275  		{Value: "s2"},
   276  	},
   277  
   278  	SubPtrSlice: []*SubStruct{
   279  		{Value: "p1"},
   280  		{Value: "p2"},
   281  	},
   282  
   283  	SubA1: SubStructAlias{Value: "test3", Value2: "v3"},
   284  	SubA2: &SubStructAlias{Value: "test4", Value2: "v4"},
   285  
   286  	Anonymous: struct {
   287  		V string
   288  		I int
   289  	}{V: "bla", I: 5},
   290  
   291  	Anonymous1: &struct {
   292  		V string
   293  	}{V: "bla1"},
   294  
   295  	AnonymousSlice:    []struct{ V int }{{1}, {2}},
   296  	AnonymousPtrSlice: []*struct{ V int }{{3}, {4}},
   297  
   298  	Slice: []string{"test5", "test6"},
   299  }
   300  
   301  var structsString = "{" +
   302  	`"Value2":5,` +
   303  
   304  	`"substruct":{"Value":"test1","Value2":"v"},` +
   305  	`"Sub2":{"Value":"test2","Value2":"v2"},` +
   306  	`"SubNil":null,` +
   307  
   308  	`"SubSlice":[{"Value":"s1","Value2":""},{"Value":"s2","Value2":""}],` +
   309  	`"SubSliceNil":null,` +
   310  
   311  	`"SubPtrSlice":[{"Value":"p1","Value2":""},{"Value":"p2","Value2":""}],` +
   312  	`"SubPtrSliceNil":null,` +
   313  
   314  	`"SubA1":{"Value":"test3","Value2":"v3"},` +
   315  	`"SubA2":{"Value":"test4","Value2":"v4"},` +
   316  
   317  	`"Anonymous":{"V":"bla","I":5},` +
   318  	`"Anonymous1":{"V":"bla1"},` +
   319  
   320  	`"AnonymousSlice":[{"V":1},{"V":2}],` +
   321  	`"AnonymousPtrSlice":[{"V":3},{"V":4}],` +
   322  
   323  	`"Slice":["test5","test6"],` +
   324  
   325  	// Embedded fields go last.
   326  	`"V":"subp",` +
   327  	`"Value":"test"` +
   328  	"}"
   329  
   330  type OmitEmpty struct {
   331  	// NOTE: first field is empty to test comma printing.
   332  
   333  	StrE, StrNE string  `json:",omitempty"`
   334  	PtrE, PtrNE *string `json:",omitempty"`
   335  
   336  	IntNE int `json:"intField,omitempty"`
   337  	IntE  int `json:",omitempty"`
   338  
   339  	// NOTE: omitempty has no effect on non-pointer struct fields.
   340  	SubE, SubNE   SubStruct  `json:",omitempty"`
   341  	SubPE, SubPNE *SubStruct `json:",omitempty"`
   342  }
   343  
   344  var omitEmptyValue = OmitEmpty{
   345  	StrNE:  "str",
   346  	PtrNE:  &str,
   347  	IntNE:  6,
   348  	SubNE:  SubStruct{Value: "1", Value2: "2"},
   349  	SubPNE: &SubStruct{Value: "3", Value2: "4"},
   350  }
   351  
   352  var omitEmptyString = "{" +
   353  	`"StrNE":"str",` +
   354  	`"PtrNE":"bla",` +
   355  	`"intField":6,` +
   356  	`"SubE":{"Value":"","Value2":""},` +
   357  	`"SubNE":{"Value":"1","Value2":"2"},` +
   358  	`"SubPNE":{"Value":"3","Value2":"4"}` +
   359  	"}"
   360  
   361  type Opts struct {
   362  	StrNull      opt.String
   363  	StrEmpty     opt.String
   364  	Str          opt.String
   365  	StrOmitempty opt.String `json:",omitempty"`
   366  
   367  	IntNull opt.Int
   368  	IntZero opt.Int
   369  	Int     opt.Int
   370  }
   371  
   372  var optsValue = Opts{
   373  	StrEmpty: opt.OString(""),
   374  	Str:      opt.OString("test"),
   375  
   376  	IntZero: opt.OInt(0),
   377  	Int:     opt.OInt(5),
   378  }
   379  
   380  var optsString = `{` +
   381  	`"StrNull":null,` +
   382  	`"StrEmpty":"",` +
   383  	`"Str":"test",` +
   384  	`"IntNull":null,` +
   385  	`"IntZero":0,` +
   386  	`"Int":5` +
   387  	`}`
   388  
   389  type Raw struct {
   390  	Field  easyjson.RawMessage
   391  	Field2 string
   392  }
   393  
   394  var rawValue = Raw{
   395  	Field:  []byte(`{"a" : "b"}`),
   396  	Field2: "test",
   397  }
   398  
   399  var rawString = `{` +
   400  	`"Field":{"a" : "b"},` +
   401  	`"Field2":"test"` +
   402  	`}`
   403  
   404  type StdMarshaler struct {
   405  	T  time.Time
   406  	IP net.IP
   407  }
   408  
   409  var stdMarshalerValue = StdMarshaler{
   410  	T:  time.Date(2016, 01, 02, 14, 15, 10, 0, time.UTC),
   411  	IP: net.IPv4(192, 168, 0, 1),
   412  }
   413  var stdMarshalerString = `{` +
   414  	`"T":"2016-01-02T14:15:10Z",` +
   415  	`"IP":"192.168.0.1"` +
   416  	`}`
   417  
   418  type UserMarshaler struct {
   419  	V vMarshaler
   420  	T tMarshaler
   421  }
   422  
   423  type vMarshaler net.IP
   424  
   425  func (v vMarshaler) MarshalJSON() ([]byte, error) {
   426  	return []byte(`"0::0"`), nil
   427  }
   428  
   429  func (v *vMarshaler) UnmarshalJSON([]byte) error {
   430  	*v = vMarshaler(net.IPv6zero)
   431  	return nil
   432  }
   433  
   434  type tMarshaler net.IP
   435  
   436  func (v tMarshaler) MarshalText() ([]byte, error) {
   437  	return []byte(`[0::0]`), nil
   438  }
   439  
   440  func (v *tMarshaler) UnmarshalText([]byte) error {
   441  	*v = tMarshaler(net.IPv6zero)
   442  	return nil
   443  }
   444  
   445  var userMarshalerValue = UserMarshaler{
   446  	V: vMarshaler(net.IPv6zero),
   447  	T: tMarshaler(net.IPv6zero),
   448  }
   449  var userMarshalerString = `{` +
   450  	`"V":"0::0",` +
   451  	`"T":"[0::0]"` +
   452  	`}`
   453  
   454  type unexportedStruct struct {
   455  	Value string
   456  }
   457  
   458  var unexportedStructValue = unexportedStruct{"test"}
   459  var unexportedStructString = `{"Value":"test"}`
   460  
   461  type ExcludedField struct {
   462  	Process       bool `json:"process"`
   463  	DoNotProcess  bool `json:"-"`
   464  	DoNotProcess1 bool `json:"-"`
   465  }
   466  
   467  var excludedFieldValue = ExcludedField{
   468  	Process:       true,
   469  	DoNotProcess:  false,
   470  	DoNotProcess1: false,
   471  }
   472  var excludedFieldString = `{"process":true}`
   473  
   474  type Slices struct {
   475  	ByteSlice      []byte
   476  	EmptyByteSlice []byte
   477  	NilByteSlice   []byte
   478  	IntSlice       []int
   479  	EmptyIntSlice  []int
   480  	NilIntSlice    []int
   481  }
   482  
   483  var sliceValue = Slices{
   484  	ByteSlice:      []byte("abc"),
   485  	EmptyByteSlice: []byte{},
   486  	NilByteSlice:   []byte(nil),
   487  	IntSlice:       []int{1, 2, 3, 4, 5},
   488  	EmptyIntSlice:  []int{},
   489  	NilIntSlice:    []int(nil),
   490  }
   491  
   492  var sliceString = `{` +
   493  	`"ByteSlice":"YWJj",` +
   494  	`"EmptyByteSlice":"",` +
   495  	`"NilByteSlice":null,` +
   496  	`"IntSlice":[1,2,3,4,5],` +
   497  	`"EmptyIntSlice":[],` +
   498  	`"NilIntSlice":null` +
   499  	`}`
   500  
   501  type Arrays struct {
   502  	ByteArray      [3]byte
   503  	EmptyByteArray [0]byte
   504  	IntArray       [5]int
   505  	EmptyIntArray  [0]int
   506  }
   507  
   508  var arrayValue = Arrays{
   509  	ByteArray:      [3]byte{'a', 'b', 'c'},
   510  	EmptyByteArray: [0]byte{},
   511  	IntArray:       [5]int{1, 2, 3, 4, 5},
   512  	EmptyIntArray:  [0]int{},
   513  }
   514  
   515  var arrayString = `{` +
   516  	`"ByteArray":"YWJj",` +
   517  	`"EmptyByteArray":"",` +
   518  	`"IntArray":[1,2,3,4,5],` +
   519  	`"EmptyIntArray":[]` +
   520  	`}`
   521  
   522  var arrayOverflowString = `{` +
   523  	`"ByteArray":"YWJjbnNk",` +
   524  	`"EmptyByteArray":"YWJj",` +
   525  	`"IntArray":[1,2,3,4,5,6],` +
   526  	`"EmptyIntArray":[7,8]` +
   527  	`}`
   528  
   529  var arrayUnderflowValue = Arrays{
   530  	ByteArray:      [3]byte{'x', 0, 0},
   531  	EmptyByteArray: [0]byte{},
   532  	IntArray:       [5]int{1, 2, 0, 0, 0},
   533  	EmptyIntArray:  [0]int{},
   534  }
   535  
   536  var arrayUnderflowString = `{` +
   537  	`"ByteArray":"eA==",` +
   538  	`"IntArray":[1,2]` +
   539  	`}`
   540  
   541  type Str string
   542  
   543  type Maps struct {
   544  	Map          map[string]string
   545  	InterfaceMap map[string]interface{}
   546  	NilMap       map[string]string
   547  
   548  	CustomMap map[Str]Str
   549  }
   550  
   551  var mapsValue = Maps{
   552  	Map:          map[string]string{"A": "b"}, // only one item since map iteration is randomized
   553  	InterfaceMap: map[string]interface{}{"G": float64(1)},
   554  
   555  	CustomMap: map[Str]Str{"c": "d"},
   556  }
   557  
   558  var mapsString = `{` +
   559  	`"Map":{"A":"b"},` +
   560  	`"InterfaceMap":{"G":1},` +
   561  	`"NilMap":null,` +
   562  	`"CustomMap":{"c":"d"}` +
   563  	`}`
   564  
   565  type NamedSlice []Str
   566  type NamedMap map[Str]Str
   567  
   568  type DeepNest struct {
   569  	SliceMap         map[Str][]Str
   570  	SliceMap1        map[Str][]Str
   571  	SliceMap2        map[Str][]Str
   572  	NamedSliceMap    map[Str]NamedSlice
   573  	NamedMapMap      map[Str]NamedMap
   574  	MapSlice         []map[Str]Str
   575  	NamedSliceSlice  []NamedSlice
   576  	NamedMapSlice    []NamedMap
   577  	NamedStringSlice []NamedString
   578  }
   579  
   580  var deepNestValue = DeepNest{
   581  	SliceMap: map[Str][]Str{
   582  		"testSliceMap": {
   583  			"0",
   584  			"1",
   585  		},
   586  	},
   587  	SliceMap1: map[Str][]Str{
   588  		"testSliceMap1": []Str(nil),
   589  	},
   590  	SliceMap2: map[Str][]Str{
   591  		"testSliceMap2": {},
   592  	},
   593  	NamedSliceMap: map[Str]NamedSlice{
   594  		"testNamedSliceMap": {
   595  			"2",
   596  			"3",
   597  		},
   598  	},
   599  	NamedMapMap: map[Str]NamedMap{
   600  		"testNamedMapMap": {
   601  			"key1": "value1",
   602  		},
   603  	},
   604  	MapSlice: []map[Str]Str{
   605  		{
   606  			"testMapSlice": "someValue",
   607  		},
   608  	},
   609  	NamedSliceSlice: []NamedSlice{
   610  		{
   611  			"someValue1",
   612  			"someValue2",
   613  		},
   614  		{
   615  			"someValue3",
   616  			"someValue4",
   617  		},
   618  	},
   619  	NamedMapSlice: []NamedMap{
   620  		{
   621  			"key2": "value2",
   622  		},
   623  		{
   624  			"key3": "value3",
   625  		},
   626  	},
   627  	NamedStringSlice: []NamedString{
   628  		"value4", "value5",
   629  	},
   630  }
   631  
   632  var deepNestString = `{` +
   633  	`"SliceMap":{` +
   634  	`"testSliceMap":["0","1"]` +
   635  	`},` +
   636  	`"SliceMap1":{` +
   637  	`"testSliceMap1":null` +
   638  	`},` +
   639  	`"SliceMap2":{` +
   640  	`"testSliceMap2":[]` +
   641  	`},` +
   642  	`"NamedSliceMap":{` +
   643  	`"testNamedSliceMap":["2","3"]` +
   644  	`},` +
   645  	`"NamedMapMap":{` +
   646  	`"testNamedMapMap":{"key1":"value1"}` +
   647  	`},` +
   648  	`"MapSlice":[` +
   649  	`{"testMapSlice":"someValue"}` +
   650  	`],` +
   651  	`"NamedSliceSlice":[` +
   652  	`["someValue1","someValue2"],` +
   653  	`["someValue3","someValue4"]` +
   654  	`],` +
   655  	`"NamedMapSlice":[` +
   656  	`{"key2":"value2"},` +
   657  	`{"key3":"value3"}` +
   658  	`],` +
   659  	`"NamedStringSlice":["value4","value5"]` +
   660  	`}`
   661  
   662  type DeepNestOptional struct {
   663  	MapSlice []map[Str]Str `json:",omitempty"`
   664  }
   665  
   666  var deepNestOptionalValue = DeepNestOptional{
   667  	MapSlice: []map[Str]Str{{}},
   668  }
   669  
   670  var deepNestOptionalString = `{` +
   671  	`"MapSlice":[` +
   672  	`{}` +
   673  	`]` +
   674  	`}`
   675  
   676  //easyjson:json
   677  type Ints []int
   678  
   679  var IntsValue = Ints{1, 2, 3, 4, 5}
   680  
   681  var IntsString = `[1,2,3,4,5]`
   682  
   683  //easyjson:json
   684  type MapStringString map[string]string
   685  
   686  var mapStringStringValue = MapStringString{"a": "b"}
   687  
   688  var mapStringStringString = `{"a":"b"}`
   689  
   690  type RequiredOptionalStruct struct {
   691  	FirstName string `json:"first_name,required"`
   692  	Lastname  string `json:"last_name"`
   693  }
   694  
   695  type RequiredOptionalMap struct {
   696  	ReqMap         map[int]string `json:"req_map,required"`
   697  	OmitEmptyMap   map[int]string `json:"oe_map,omitempty"`
   698  	NoOmitEmptyMap map[int]string `json:"noe_map,!omitempty"`
   699  }
   700  
   701  //easyjson:json
   702  type EncodingFlagsTestMap struct {
   703  	F map[string]string
   704  }
   705  
   706  //easyjson:json
   707  type EncodingFlagsTestSlice struct {
   708  	F []string
   709  }
   710  
   711  type StructWithInterface struct {
   712  	Field1 int         `json:"f1"`
   713  	Field2 interface{} `json:"f2"`
   714  	Field3 string      `json:"f3"`
   715  }
   716  
   717  type EmbeddedStruct struct {
   718  	Field1 int    `json:"f1"`
   719  	Field2 string `json:"f2"`
   720  }
   721  
   722  var structWithInterfaceString = `{"f1":1,"f2":{"f1":11,"f2":"22"},"f3":"3"}`
   723  var structWithInterfaceValueFilled = StructWithInterface{1, &EmbeddedStruct{11, "22"}, "3"}
   724  
   725  //easyjson:json
   726  type MapIntString map[int]string
   727  
   728  var mapIntStringValue = MapIntString{3: "hi"}
   729  var mapIntStringValueString = `{"3":"hi"}`
   730  
   731  //easyjson:json
   732  type MapInt32String map[int32]string
   733  
   734  var mapInt32StringValue = MapInt32String{-354634382: "life"}
   735  var mapInt32StringValueString = `{"-354634382":"life"}`
   736  
   737  //easyjson:json
   738  type MapInt64String map[int64]string
   739  
   740  var mapInt64StringValue = MapInt64String{-3546343826724305832: "life"}
   741  var mapInt64StringValueString = `{"-3546343826724305832":"life"}`
   742  
   743  //easyjson:json
   744  type MapUintString map[uint]string
   745  
   746  var mapUintStringValue = MapUintString{42: "life"}
   747  var mapUintStringValueString = `{"42":"life"}`
   748  
   749  //easyjson:json
   750  type MapUint32String map[uint32]string
   751  
   752  var mapUint32StringValue = MapUint32String{354634382: "life"}
   753  var mapUint32StringValueString = `{"354634382":"life"}`
   754  
   755  //easyjson:json
   756  type MapUint64String map[uint64]string
   757  
   758  var mapUint64StringValue = MapUint64String{3546343826724305832: "life"}
   759  var mapUint64StringValueString = `{"3546343826724305832":"life"}`
   760  
   761  //easyjson:json
   762  type MapUintptrString map[uintptr]string
   763  
   764  var mapUintptrStringValue = MapUintptrString{272679208: "obj"}
   765  var mapUintptrStringValueString = `{"272679208":"obj"}`
   766  
   767  type MyInt int
   768  
   769  //easyjson:json
   770  type MapMyIntString map[MyInt]string
   771  
   772  var mapMyIntStringValue = MapMyIntString{MyInt(42): "life"}
   773  var mapMyIntStringValueString = `{"42":"life"}`
   774  
   775  //easyjson:json
   776  type IntKeyedMapStruct struct {
   777  	Foo MapMyIntString            `json:"foo"`
   778  	Bar map[int16]MapUint32String `json:"bar"`
   779  }
   780  
   781  var intKeyedMapStructValue = IntKeyedMapStruct{
   782  	Foo: mapMyIntStringValue,
   783  	Bar: map[int16]MapUint32String{32: mapUint32StringValue},
   784  }
   785  var intKeyedMapStructValueString = `{` +
   786  	`"foo":{"42":"life"},` +
   787  	`"bar":{"32":{"354634382":"life"}}` +
   788  	`}`
   789  
   790  type IntArray [2]int
   791  
   792  //easyjson:json
   793  type IntArrayStruct struct {
   794  	Pointer *IntArray `json:"pointer"`
   795  	Value   IntArray  `json:"value"`
   796  }
   797  
   798  var intArrayStructValue = IntArrayStruct{
   799  	Pointer: &IntArray{1, 2},
   800  	Value:   IntArray{1, 2},
   801  }
   802  
   803  var intArrayStructValueString = `{` +
   804  	`"pointer":[1,2],` +
   805  	`"value":[1,2]` +
   806  	`}`
   807  
   808  type MyUInt8 uint8
   809  
   810  //easyjson:json
   811  type MyUInt8Slice []MyUInt8
   812  
   813  var myUInt8SliceValue = MyUInt8Slice{1, 2, 3, 4, 5}
   814  
   815  var myUInt8SliceString = `[1,2,3,4,5]`
   816  
   817  //easyjson:json
   818  type MyUInt8Array [2]MyUInt8
   819  
   820  var myUInt8ArrayValue = MyUInt8Array{1, 2}
   821  
   822  var myUInt8ArrayString = `[1,2]`
   823  

View as plain text