| 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 |
CustomMapWithEmptyKey map[Str]Str |
| 550 |
} |
| 551 |
|
| 552 |
var mapsValue = Maps{ |
| 553 |
Map: map[string]string{"A": "b"}, // only one item since map iteration is randomized |
| 554 |
InterfaceMap: map[string]interface{}{"G": float64(1)}, |
| 555 |
|
| 556 |
CustomMap: map[Str]Str{"c": "d"}, |
| 557 |
CustomMapWithEmptyKey: map[Str]Str{"": "d"}, |
| 558 |
} |
| 559 |
|
| 560 |
var mapsString = `{` + |
| 561 |
`"Map":{"A":"b"},` + |
| 562 |
`"InterfaceMap":{"G":1},` + |
| 563 |
`"NilMap":null,` + |
| 564 |
`"CustomMap":{"c":"d"},` + |
| 565 |
`"CustomMapWithEmptyKey":{"":"d"}` + |
| 566 |
`}` |
| 567 |
|
| 568 |
type NamedSlice []Str |
| 569 |
type NamedMap map[Str]Str |
| 570 |
|
| 571 |
type DeepNest struct { |
| 572 |
SliceMap map[Str][]Str |
| 573 |
SliceMap1 map[Str][]Str |
| 574 |
SliceMap2 map[Str][]Str |
| 575 |
NamedSliceMap map[Str]NamedSlice |
| 576 |
NamedMapMap map[Str]NamedMap |
| 577 |
MapSlice []map[Str]Str |
| 578 |
NamedSliceSlice []NamedSlice |
| 579 |
NamedMapSlice []NamedMap |
| 580 |
NamedStringSlice []NamedString |
| 581 |
} |
| 582 |
|
| 583 |
var deepNestValue = DeepNest{ |
| 584 |
SliceMap: map[Str][]Str{ |
| 585 |
"testSliceMap": { |
| 586 |
"0", |
| 587 |
"1", |
| 588 |
}, |
| 589 |
}, |
| 590 |
SliceMap1: map[Str][]Str{ |
| 591 |
"testSliceMap1": []Str(nil), |
| 592 |
}, |
| 593 |
SliceMap2: map[Str][]Str{ |
| 594 |
"testSliceMap2": {}, |
| 595 |
}, |
| 596 |
NamedSliceMap: map[Str]NamedSlice{ |
| 597 |
"testNamedSliceMap": { |
| 598 |
"2", |
| 599 |
"3", |
| 600 |
}, |
| 601 |
}, |
| 602 |
NamedMapMap: map[Str]NamedMap{ |
| 603 |
"testNamedMapMap": { |
| 604 |
"key1": "value1", |
| 605 |
}, |
| 606 |
}, |
| 607 |
MapSlice: []map[Str]Str{ |
| 608 |
{ |
| 609 |
"testMapSlice": "someValue", |
| 610 |
}, |
| 611 |
}, |
| 612 |
NamedSliceSlice: []NamedSlice{ |
| 613 |
{ |
| 614 |
"someValue1", |
| 615 |
"someValue2", |
| 616 |
}, |
| 617 |
{ |
| 618 |
"someValue3", |
| 619 |
"someValue4", |
| 620 |
}, |
| 621 |
}, |
| 622 |
NamedMapSlice: []NamedMap{ |
| 623 |
{ |
| 624 |
"key2": "value2", |
| 625 |
}, |
| 626 |
{ |
| 627 |
"key3": "value3", |
| 628 |
}, |
| 629 |
}, |
| 630 |
NamedStringSlice: []NamedString{ |
| 631 |
"value4", "value5", |
| 632 |
}, |
| 633 |
} |
| 634 |
|
| 635 |
var deepNestString = `{` + |
| 636 |
`"SliceMap":{` + |
| 637 |
`"testSliceMap":["0","1"]` + |
| 638 |
`},` + |
| 639 |
`"SliceMap1":{` + |
| 640 |
`"testSliceMap1":null` + |
| 641 |
`},` + |
| 642 |
`"SliceMap2":{` + |
| 643 |
`"testSliceMap2":[]` + |
| 644 |
`},` + |
| 645 |
`"NamedSliceMap":{` + |
| 646 |
`"testNamedSliceMap":["2","3"]` + |
| 647 |
`},` + |
| 648 |
`"NamedMapMap":{` + |
| 649 |
`"testNamedMapMap":{"key1":"value1"}` + |
| 650 |
`},` + |
| 651 |
`"MapSlice":[` + |
| 652 |
`{"testMapSlice":"someValue"}` + |
| 653 |
`],` + |
| 654 |
`"NamedSliceSlice":[` + |
| 655 |
`["someValue1","someValue2"],` + |
| 656 |
`["someValue3","someValue4"]` + |
| 657 |
`],` + |
| 658 |
`"NamedMapSlice":[` + |
| 659 |
`{"key2":"value2"},` + |
| 660 |
`{"key3":"value3"}` + |
| 661 |
`],` + |
| 662 |
`"NamedStringSlice":["value4","value5"]` + |
| 663 |
`}` |
| 664 |
|
| 665 |
type DeepNestOptional struct { |
| 666 |
MapSlice []map[Str]Str `json:",omitempty"` |
| 667 |
} |
| 668 |
|
| 669 |
var deepNestOptionalValue = DeepNestOptional{ |
| 670 |
MapSlice: []map[Str]Str{{}}, |
| 671 |
} |
| 672 |
|
| 673 |
var deepNestOptionalString = `{` + |
| 674 |
`"MapSlice":[` + |
| 675 |
`{}` + |
| 676 |
`]` + |
| 677 |
`}` |
| 678 |
|
| 679 |
//easyjson:json |
| 680 |
type Ints []int |
| 681 |
|
| 682 |
var IntsValue = Ints{1, 2, 3, 4, 5} |
| 683 |
|
| 684 |
var IntsString = `[1,2,3,4,5]` |
| 685 |
|
| 686 |
//easyjson:json |
| 687 |
type MapStringString map[string]string |
| 688 |
|
| 689 |
var mapStringStringValue = MapStringString{"a": "b"} |
| 690 |
|
| 691 |
var mapStringStringString = `{"a":"b"}` |
| 692 |
|
| 693 |
type RequiredOptionalStruct struct { |
| 694 |
FirstName string `json:"first_name,required"` |
| 695 |
Lastname string `json:"last_name"` |
| 696 |
} |
| 697 |
|
| 698 |
type RequiredOptionalMap struct { |
| 699 |
ReqMap map[int]string `json:"req_map,required"` |
| 700 |
OmitEmptyMap map[int]string `json:"oe_map,omitempty"` |
| 701 |
NoOmitEmptyMap map[int]string `json:"noe_map,!omitempty"` |
| 702 |
} |
| 703 |
|
| 704 |
//easyjson:json |
| 705 |
type EncodingFlagsTestMap struct { |
| 706 |
F map[string]string |
| 707 |
} |
| 708 |
|
| 709 |
//easyjson:json |
| 710 |
type EncodingFlagsTestSlice struct { |
| 711 |
F []string |
| 712 |
} |
| 713 |
|
| 714 |
type StructWithInterface struct { |
| 715 |
Field1 int `json:"f1"` |
| 716 |
Field2 interface{} `json:"f2"` |
| 717 |
Field3 string `json:"f3"` |
| 718 |
} |
| 719 |
|
| 720 |
type EmbeddedStruct struct { |
| 721 |
Field1 int `json:"f1"` |
| 722 |
Field2 string `json:"f2"` |
| 723 |
} |
| 724 |
|
| 725 |
var structWithInterfaceString = `{"f1":1,"f2":{"f1":11,"f2":"22"},"f3":"3"}` |
| 726 |
var structWithInterfaceValueFilled = StructWithInterface{1, &EmbeddedStruct{11, "22"}, "3"} |
| 727 |
|
| 728 |
//easyjson:json |
| 729 |
type MapIntString map[int]string |
| 730 |
|
| 731 |
var mapIntStringValue = MapIntString{3: "hi"} |
| 732 |
var mapIntStringValueString = `{"3":"hi"}` |
| 733 |
|
| 734 |
//easyjson:json |
| 735 |
type MapInt32String map[int32]string |
| 736 |
|
| 737 |
var mapInt32StringValue = MapInt32String{-354634382: "life"} |
| 738 |
var mapInt32StringValueString = `{"-354634382":"life"}` |
| 739 |
|
| 740 |
//easyjson:json |
| 741 |
type MapInt64String map[int64]string |
| 742 |
|
| 743 |
var mapInt64StringValue = MapInt64String{-3546343826724305832: "life"} |
| 744 |
var mapInt64StringValueString = `{"-3546343826724305832":"life"}` |
| 745 |
|
| 746 |
//easyjson:json |
| 747 |
type MapUintString map[uint]string |
| 748 |
|
| 749 |
var mapUintStringValue = MapUintString{42: "life"} |
| 750 |
var mapUintStringValueString = `{"42":"life"}` |
| 751 |
|
| 752 |
//easyjson:json |
| 753 |
type MapUint32String map[uint32]string |
| 754 |
|
| 755 |
var mapUint32StringValue = MapUint32String{354634382: "life"} |
| 756 |
var mapUint32StringValueString = `{"354634382":"life"}` |
| 757 |
|
| 758 |
//easyjson:json |
| 759 |
type MapUint64String map[uint64]string |
| 760 |
|
| 761 |
var mapUint64StringValue = MapUint64String{3546343826724305832: "life"} |
| 762 |
var mapUint64StringValueString = `{"3546343826724305832":"life"}` |
| 763 |
|
| 764 |
//easyjson:json |
| 765 |
type MapUintptrString map[uintptr]string |
| 766 |
|
| 767 |
var mapUintptrStringValue = MapUintptrString{272679208: "obj"} |
| 768 |
var mapUintptrStringValueString = `{"272679208":"obj"}` |
| 769 |
|
| 770 |
type MyInt int |
| 771 |
|
| 772 |
//easyjson:json |
| 773 |
type MapMyIntString map[MyInt]string |
| 774 |
|
| 775 |
var mapMyIntStringValue = MapMyIntString{MyInt(42): "life"} |
| 776 |
var mapMyIntStringValueString = `{"42":"life"}` |
| 777 |
|
| 778 |
//easyjson:json |
| 779 |
type IntKeyedMapStruct struct { |
| 780 |
Foo MapMyIntString `json:"foo"` |
| 781 |
Bar map[int16]MapUint32String `json:"bar"` |
| 782 |
} |
| 783 |
|
| 784 |
var intKeyedMapStructValue = IntKeyedMapStruct{ |
| 785 |
Foo: mapMyIntStringValue, |
| 786 |
Bar: map[int16]MapUint32String{32: mapUint32StringValue}, |
| 787 |
} |
| 788 |
var intKeyedMapStructValueString = `{` + |
| 789 |
`"foo":{"42":"life"},` + |
| 790 |
`"bar":{"32":{"354634382":"life"}}` + |
| 791 |
`}` |
| 792 |
|
| 793 |
type IntArray [2]int |
| 794 |
|
| 795 |
//easyjson:json |
| 796 |
type IntArrayStruct struct { |
| 797 |
Pointer *IntArray `json:"pointer"` |
| 798 |
Value IntArray `json:"value"` |
| 799 |
} |
| 800 |
|
| 801 |
var intArrayStructValue = IntArrayStruct{ |
| 802 |
Pointer: &IntArray{1, 2}, |
| 803 |
Value: IntArray{1, 2}, |
| 804 |
} |
| 805 |
|
| 806 |
var intArrayStructValueString = `{` + |
| 807 |
`"pointer":[1,2],` + |
| 808 |
`"value":[1,2]` + |
| 809 |
`}` |
| 810 |
|
| 811 |
type MyUInt8 uint8 |
| 812 |
|
| 813 |
//easyjson:json |
| 814 |
type MyUInt8Slice []MyUInt8 |
| 815 |
|
| 816 |
var myUInt8SliceValue = MyUInt8Slice{1, 2, 3, 4, 5} |
| 817 |
|
| 818 |
var myUInt8SliceString = `[1,2,3,4,5]` |
| 819 |
|
| 820 |
//easyjson:json |
| 821 |
type MyUInt8Array [2]MyUInt8 |
| 822 |
|
| 823 |
var myUInt8ArrayValue = MyUInt8Array{1, 2} |
| 824 |
|
| 825 |
var myUInt8ArrayString = `[1,2]` |