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 (*struct { 125 F1 string `json:"F1"` 126 F2 string `json:"F2,string"` 127 })(nil), 128 (*struct { 129 F1 uint8 `json:"F1"` 130 F2 uint8 `json:"F2,string"` 131 })(nil), 132 (*struct { 133 F1 uint16 `json:"F1"` 134 F2 uint16 `json:"F2,string"` 135 })(nil), 136 (*struct { 137 F1 uint32 `json:"F1"` 138 F2 uint32 `json:"F2,string"` 139 })(nil), 140 (*struct { 141 A string `json:"a,omitempty"` 142 B string `json:"b,omitempty"` 143 Annotations map[string]string `json:"annotations,omitempty"` 144 })(nil), 145 (*struct { 146 Field bool `json:",omitempty,string"` 147 })(nil), 148 (*struct { 149 Field bool `json:"中文"` 150 })(nil), 151 ) 152} 153 154// S1 TEST ONLY 155type EmbeddedFieldNameS1 struct { 156 S1F string 157} 158 159// S2 TEST ONLY 160type EmbeddedFieldNameS2 struct { 161 S2F string 162} 163 164// S3 TEST ONLY 165type EmbeddedFieldNameS3 struct { 166 S3F string 167} 168 169// S4 TEST ONLY 170type EmbeddedFieldNameS4 struct { 171 S4F string 172} 173 174// S5 TEST ONLY 175type EmbeddedFieldNameS5 struct { 176 S5F string 177} 178 179// S6 TEST ONLY 180type EmbeddedFieldNameS6 struct { 181 S6F string 182} 183 184type EmbeddedFieldName struct { 185 EmbeddedFieldNameS1 `json:"F1"` 186 EmbeddedFieldNameS2 `json:"f2"` 187 EmbeddedFieldNameS3 `json:"-"` 188 EmbeddedFieldNameS4 `json:"-,"` 189 EmbeddedFieldNameS5 `json:","` 190 EmbeddedFieldNameS6 `json:""` 191} 192 193type StringFieldNameE struct { 194 E1 string 195} 196 197type StringFieldName struct { 198 F1 string `json:"F1"` 199 F2 string `json:"f2"` 200 F3 string `json:"-"` 201 F4 string `json:"-,"` 202 F5 string `json:","` 203 F6 string `json:""` 204 StringFieldNameE `json:"e"` 205} 206 207type StructFieldNameS1 struct { 208 S1F string 209} 210 211type StructFieldNameS2 struct { 212 S2F string 213} 214 215type StructFieldNameS3 struct { 216 S3F string 217} 218 219type StructFieldNameS4 struct { 220 S4F string 221} 222 223type StructFieldNameS5 struct { 224 S5F string 225} 226 227type StructFieldNameS6 struct { 228 S6F string 229} 230 231type StructFieldName struct { 232 F1 StructFieldNameS1 `json:"F1"` 233 F2 StructFieldNameS2 `json:"f2"` 234 F3 StructFieldNameS3 `json:"-"` 235 F4 StructFieldNameS4 `json:"-,"` 236 F5 StructFieldNameS5 `json:","` 237 F6 StructFieldNameS6 `json:""` 238} 239type EmbeddedOmitEmptyE struct { 240 F string `json:"F,omitempty"` 241} 242 243type EmbeddedOmitEmpty struct { 244 EmbeddedOmitEmptyE 245} 246 247type jm string 248 249func (t *jm) UnmarshalJSON(b []byte) error { 250 return nil 251} 252 253func (t jm) MarshalJSON() ([]byte, error) { 254 return []byte(`""`), nil 255} 256 257type tm string 258 259func (t *tm) UnmarshalText(b []byte) error { 260 return nil 261} 262 263func (t tm) MarshalText() ([]byte, error) { 264 return []byte(`""`), nil 265} 266 267type sjm struct{} 268 269func (t *sjm) UnmarshalJSON(b []byte) error { 270 return nil 271} 272 273func (t sjm) MarshalJSON() ([]byte, error) { 274 return []byte(`""`), nil 275} 276 277type stm struct{} 278 279func (t *stm) UnmarshalText(b []byte) error { 280 return nil 281} 282 283func (t stm) MarshalText() ([]byte, error) { 284 return []byte(`""`), nil 285} 286