struct_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package test
  2. import (
  3. "time"
  4. "encoding/json"
  5. )
  6. func init() {
  7. unmarshalCases = append(unmarshalCases, unmarshalCase{
  8. ptr: (*struct {
  9. Field interface{}
  10. })(nil),
  11. input: `{"Field": "hello"}`,
  12. }, unmarshalCase{
  13. ptr: (*struct {
  14. Field int `json:"field"`
  15. })(nil),
  16. input: `{"field": null}`,
  17. })
  18. marshalCases = append(marshalCases,
  19. struct {
  20. Field map[string]interface{}
  21. }{
  22. map[string]interface{}{"hello": "world"},
  23. },
  24. struct {
  25. Field map[string]interface{}
  26. Field2 string
  27. }{
  28. map[string]interface{}{"hello": "world"}, "",
  29. },
  30. struct {
  31. Field interface{}
  32. }{
  33. 1024,
  34. },
  35. struct {
  36. Field MyInterface
  37. }{
  38. MyString("hello"),
  39. },
  40. struct {
  41. F *float64
  42. }{},
  43. // TODO: fix this
  44. //struct {
  45. // *time.Time
  46. //}{},
  47. struct {
  48. *time.Time
  49. }{&time.Time{}},
  50. struct {
  51. *StructVarious
  52. }{&StructVarious{}},
  53. struct {
  54. *StructVarious
  55. }{},
  56. struct {
  57. Field1 int
  58. Field2 [1]*float64
  59. }{},
  60. struct {
  61. Field interface{} `json:"field,omitempty"`
  62. }{},
  63. struct {
  64. Field MyInterface `json:"field,omitempty"`
  65. }{},
  66. struct {
  67. Field MyInterface `json:"field,omitempty"`
  68. }{MyString("hello")},
  69. struct {
  70. Field json.Marshaler `json:"field"`
  71. }{},
  72. struct {
  73. Field MyInterface `json:"field"`
  74. }{},
  75. struct {
  76. Field MyInterface `json:"field"`
  77. }{MyString("hello")},
  78. )
  79. }
  80. type StructVarious struct {
  81. Field0 string
  82. Field1 []string
  83. Field2 map[string]interface{}
  84. }