@@ -105,6 +105,18 @@ func init() {
105
105
Asks [][2 ]float64 `json:"asks"`
106
106
})(nil ),
107
107
input : `{"key_string": "KEYSTRING","type": "TYPE","asks": [[1e+66,1]]}` ,
108
+ }, unmarshalCase {
109
+ ptr : (* quote )(nil ),
110
+ input : `{"Str":null,"F32":null,"F64":null,"Int":null,"Uint":null,"I16":null,"I32":null,"I64":null,"U8":null,"U16":null,"U32":null,"U64":null,"Uptr":null,"Bool":null}` ,
111
+ }, unmarshalCase {
112
+ ptr : (* quote )(nil ),
113
+ input : `{"Str":"\"foo\""}` ,
114
+ }, unmarshalCase {
115
+ ptr : (* struct {
116
+ AnyStr interface {} `json:",string"`
117
+ AnyInt interface {} `json:",string"`
118
+ })(nil ),
119
+ input : `{"AnyStr":"foo","AnyInt":123}` ,
108
120
})
109
121
marshalCases = append (marshalCases ,
110
122
struct {
@@ -204,6 +216,14 @@ func init() {
204
216
}{
205
217
"should not marshal" ,
206
218
},
219
+ quote {},
220
+ struct {
221
+ AnyStr interface {} `json:",string"`
222
+ AnyInt interface {} `json:",string"`
223
+ }{
224
+ AnyStr : "foo" ,
225
+ AnyInt : 123 ,
226
+ },
207
227
)
208
228
}
209
229
@@ -245,3 +265,23 @@ type structOrder struct {
245
265
orderB
246
266
Field7 string
247
267
}
268
+
269
+ type quote struct {
270
+ // The ,string option applies only to fields of string, floating point, integer,
271
+ // or boolean types as per https://pkg.go.dev/encoding/[email protected] .
272
+ // It is poorly or not totally documented that json.Marshal does not quote null.
273
+ Str * string `json:",string"`
274
+ F32 * float32 `json:",string"`
275
+ F64 * float64 `json:",string"`
276
+ Int * int `json:",string"`
277
+ Uint * uint `json:",string"`
278
+ I16 * int16 `json:",string"`
279
+ I32 * int32 `json:",string"`
280
+ I64 * int64 `json:",string"`
281
+ U8 * uint8 `json:",string"`
282
+ U16 * uint16 `json:",string"`
283
+ U32 * uint32 `json:",string"`
284
+ U64 * uint64 `json:",string"`
285
+ Uptr * uintptr `json:",string"`
286
+ Bool * bool `json:",string"`
287
+ }
0 commit comments