1package test 2 3func init() { 4 testCases = append(testCases, 5 (*EmbeddedFieldName)(nil), 6 (*StringFieldName)(nil), 7 (*StructFieldName)(nil), 8 (*struct { 9 F1 bool `json:"F1"` 10 F2 bool `json:"F2,omitempty"` 11 })(nil), 12 (*EmbeddedOmitEmpty)(nil), 13 (*struct { 14 F1 float32 `json:"F1"` 15 F2 float32 `json:"F2,omitempty"` 16 })(nil), 17 (*struct { 18 F1 int32 `json:"F1"` 19 F2 int32 `json:"F2,omitempty"` 20 })(nil), 21 (*struct { 22 F1 map[string]string `json:"F1"` 23 F2 map[string]string `json:"F2,omitempty"` 24 })(nil), 25 (*struct { 26 F1 *bool `json:"F1"` 27 F2 *bool `json:"F2,omitempty"` 28 })(nil), 29 (*struct { 30 F1 *float32 `json:"F1"` 31 F2 *float32 `json:"F2,omitempty"` 32 })(nil), 33 (*struct { 34 F1 *int32 `json:"F1"` 35 F2 *int32 `json:"F2,omitempty"` 36 })(nil), 37 (*struct { 38 F1 *map[string]string `json:"F1"` 39 F2 *map[string]string `json:"F2,omitempty"` 40 })(nil), 41 (*struct { 42 F1 *[]string `json:"F1"` 43 F2 *[]string `json:"F2,omitempty"` 44 })(nil), 45 (*struct { 46 F1 string `json:"F1"` 47 F2 string `json:"F2,omitempty"` 48 })(nil), 49 (*struct { 50 F1 *string `json:"F1"` 51 F2 *string `json:"F2,omitempty"` 52 })(nil), 53 (*struct { 54 F *jm `json:"f,omitempty"` 55 })(nil), 56 (*struct { 57 F *tm `json:"f,omitempty"` 58 })(nil), 59 (*struct { 60 F *sjm `json:"f,omitempty"` 61 })(nil), 62 (*struct { 63 F *tm `json:"f,omitempty"` 64 })(nil), 65 (*struct { 66 F1 *uint32 `json:"F1"` 67 F2 *uint32 `json:"F2,omitempty"` 68 })(nil), 69 (*struct { 70 F1 []string `json:"F1"` 71 F2 []string `json:"F2,omitempty"` 72 })(nil), 73 (*struct { 74 F1 string `json:"F1"` 75 F2 string `json:"F2,omitempty"` 76 })(nil), 77 (*struct { 78 F jm `json:"f,omitempty"` 79 })(nil), 80 (*struct { 81 F tm `json:"f,omitempty"` 82 })(nil), 83 (*struct { 84 F struct{} `json:"f,omitempty"` // omitempty is meaningless here 85 })(nil), 86 (*struct { 87 F sjm `json:"f,omitempty"` 88 })(nil), 89 (*struct { 90 F stm `json:"f,omitempty"` 91 })(nil), 92 (*struct { 93 F1 uint32 `json:"F1"` 94 F2 uint32 `json:"F2,omitempty"` 95 })(nil), 96 (*struct { 97 F1 bool `json:"F1"` 98 F2 bool `json:"F2,string"` 99 })(nil), 100 (*struct { 101 F1 byte `json:"F1"` 102 F2 byte `json:"F2,string"` 103 })(nil), 104 (*struct { 105 F1 float32 `json:"F1"` 106 F2 float32 `json:"F2,string"` 107 })(nil), 108 (*struct { 109 F1 float64 `json:"F1"` 110 F2 float64 `json:"F2,string"` 111 })(nil), 112 (*struct { 113 F1 int8 `json:"F1"` 114 F2 int8 `json:"F2,string"` 115 })(nil), 116 (*struct { 117 F1 int16 `json:"F1"` 118 F2 int16 `json:"F2,string"` 119 })(nil), 120 (*struct { 121 F1 int32 `json:"F1"` 122 F2 int32 `json:"F2,string"` 123 })(nil), 124 // remove temporarily until https://github.com/golang/go/issues/38126 is fixed 125 // (*struct { 126 // F1 string `json:"F1"` 127 // F2 string `json:"F2,string"` 128 // })(nil), 129 (*struct { 130 F1 uint8 `json:"F1"` 131 F2 uint8 `json:"F2,string"` 132 })(nil), 133 (*struct { 134 F1 uint16 `json:"F1"` 135 F2 uint16 `json:"F2,string"` 136 })(nil), 137 (*struct { 138 F1 uint32 `json:"F1"` 139 F2 uint32 `json:"F2,string"` 140 })(nil), 141 (*struct { 142 A string `json:"a,omitempty"` 143 B string `json:"b,omitempty"` 144 Annotations map[string]string `json:"annotations,omitempty"` 145 })(nil), 146 (*struct { 147 Field bool `json:",omitempty,string"` 148 })(nil), 149 (*struct { 150 Field bool `json:"中文"` 151 })(nil), 152 ) 153} 154 155// S1 TEST ONLY 156type EmbeddedFieldNameS1 struct { 157 S1F string 158} 159 160// S2 TEST ONLY 161type EmbeddedFieldNameS2 struct { 162 S2F string 163} 164 165// S3 TEST ONLY 166type EmbeddedFieldNameS3 struct { 167 S3F string 168} 169 170// S4 TEST ONLY 171type EmbeddedFieldNameS4 struct { 172 S4F string 173} 174 175// S5 TEST ONLY 176type EmbeddedFieldNameS5 struct { 177 S5F string 178} 179 180// S6 TEST ONLY 181type EmbeddedFieldNameS6 struct { 182 S6F string 183} 184 185type EmbeddedFieldName struct { 186 EmbeddedFieldNameS1 `json:"F1"` 187 EmbeddedFieldNameS2 `json:"f2"` 188 EmbeddedFieldNameS3 `json:"-"` 189 EmbeddedFieldNameS4 `json:"-,"` 190 EmbeddedFieldNameS5 `json:","` 191 EmbeddedFieldNameS6 `json:""` 192} 193 194type StringFieldNameE struct { 195 E1 string 196} 197 198type StringFieldName struct { 199 F1 string `json:"F1"` 200 F2 string `json:"f2"` 201 F3 string `json:"-"` 202 F4 string `json:"-,"` 203 F5 string `json:","` 204 F6 string `json:""` 205 StringFieldNameE `json:"e"` 206} 207 208type StructFieldNameS1 struct { 209 S1F string 210} 211 212type StructFieldNameS2 struct { 213 S2F string 214} 215 216type StructFieldNameS3 struct { 217 S3F string 218} 219 220type StructFieldNameS4 struct { 221 S4F string 222} 223 224type StructFieldNameS5 struct { 225 S5F string 226} 227 228type StructFieldNameS6 struct { 229 S6F string 230} 231 232type StructFieldName struct { 233 F1 StructFieldNameS1 `json:"F1"` 234 F2 StructFieldNameS2 `json:"f2"` 235 F3 StructFieldNameS3 `json:"-"` 236 F4 StructFieldNameS4 `json:"-,"` 237 F5 StructFieldNameS5 `json:","` 238 F6 StructFieldNameS6 `json:""` 239} 240type EmbeddedOmitEmptyE struct { 241 F string `json:"F,omitempty"` 242} 243 244type EmbeddedOmitEmpty struct { 245 EmbeddedOmitEmptyE 246} 247 248type jm string 249 250func (t *jm) UnmarshalJSON(b []byte) error { 251 return nil 252} 253 254func (t jm) MarshalJSON() ([]byte, error) { 255 return []byte(`""`), nil 256} 257 258type tm string 259 260func (t *tm) UnmarshalText(b []byte) error { 261 return nil 262} 263 264func (t tm) MarshalText() ([]byte, error) { 265 return []byte(`""`), nil 266} 267 268type sjm struct{} 269 270func (t *sjm) UnmarshalJSON(b []byte) error { 271 return nil 272} 273 274func (t sjm) MarshalJSON() ([]byte, error) { 275 return []byte(`""`), nil 276} 277 278type stm struct{} 279 280func (t *stm) UnmarshalText(b []byte) error { 281 return nil 282} 283 284func (t stm) MarshalText() ([]byte, error) { 285 return []byte(`""`), nil 286} 287