1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-30 08:36:43 +02:00
json-iterator/value_tests/struct_test.go

87 lines
1.4 KiB
Go
Raw Normal View History

2018-02-13 17:49:40 +02:00
package test
import (
"time"
"encoding/json"
)
func init() {
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*struct {
Field interface{}
})(nil),
input: `{"Field": "hello"}`,
2018-02-14 02:39:18 +02:00
}, unmarshalCase{
ptr: (*struct {
Field int `json:"field"`
})(nil),
input: `{"field": null}`,
2018-02-13 17:49:40 +02:00
})
marshalCases = append(marshalCases,
struct {
Field map[string]interface{}
}{
map[string]interface{}{"hello": "world"},
},
struct {
Field map[string]interface{}
Field2 string
}{
map[string]interface{}{"hello": "world"}, "",
},
struct {
Field interface{}
}{
1024,
},
struct {
Field MyInterface
}{
MyString("hello"),
},
struct {
F *float64
}{},
// TODO: fix this
//struct {
// *time.Time
//}{},
struct {
*time.Time
}{&time.Time{}},
struct {
*StructVarious
}{&StructVarious{}},
struct {
*StructVarious
}{},
struct {
Field1 int
Field2 [1]*float64
}{},
struct {
Field interface{} `json:"field,omitempty"`
}{},
struct {
Field MyInterface `json:"field,omitempty"`
}{},
struct {
Field MyInterface `json:"field,omitempty"`
}{MyString("hello")},
struct {
Field json.Marshaler `json:"field"`
}{},
struct {
Field MyInterface `json:"field"`
}{},
struct {
Field MyInterface `json:"field"`
}{MyString("hello")},
)
}
type StructVarious struct {
Field0 string
Field1 []string
Field2 map[string]interface{}
}