mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #396 from SolidShake/fix-null-map-key
Fix null key in map
This commit is contained in:
+1
-1
@@ -242,7 +242,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT
|
||||
|
||||
// NOTE: extra check for TextMarshaler. It overrides default methods.
|
||||
if reflect.PtrTo(key).Implements(reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()) {
|
||||
fmt.Fprintln(g.out, ws+" "+fmt.Sprintf("out.RawText(("+tmpVar+"Name).MarshalText()"+")"))
|
||||
fmt.Fprintln(g.out, ws+" "+fmt.Sprintf("out.RawBytesString(("+tmpVar+"Name).MarshalText()"+")"))
|
||||
} else if keyEnc != "" {
|
||||
fmt.Fprintln(g.out, ws+" "+fmt.Sprintf(keyEnc, tmpVar+"Name"))
|
||||
} else {
|
||||
|
||||
@@ -67,6 +67,18 @@ func (w *Writer) RawString(s string) {
|
||||
w.Buffer.AppendString(s)
|
||||
}
|
||||
|
||||
// RawBytesString appends string from bytes to the buffer.
|
||||
func (w *Writer) RawBytesString(data []byte, err error) {
|
||||
switch {
|
||||
case w.Error != nil:
|
||||
return
|
||||
case err != nil:
|
||||
w.Error = err
|
||||
default:
|
||||
w.String(string(data))
|
||||
}
|
||||
}
|
||||
|
||||
// Raw appends raw binary data to the buffer or sets the error if it is given. Useful for
|
||||
// calling with results of MarshalJSON-like functions.
|
||||
func (w *Writer) Raw(data []byte, err error) {
|
||||
|
||||
+6
-3
@@ -545,21 +545,24 @@ type Maps struct {
|
||||
InterfaceMap map[string]interface{}
|
||||
NilMap map[string]string
|
||||
|
||||
CustomMap map[Str]Str
|
||||
CustomMap map[Str]Str
|
||||
CustomMapWithEmptyKey map[Str]Str
|
||||
}
|
||||
|
||||
var mapsValue = Maps{
|
||||
Map: map[string]string{"A": "b"}, // only one item since map iteration is randomized
|
||||
InterfaceMap: map[string]interface{}{"G": float64(1)},
|
||||
|
||||
CustomMap: map[Str]Str{"c": "d"},
|
||||
CustomMap: map[Str]Str{"c": "d"},
|
||||
CustomMapWithEmptyKey: map[Str]Str{"": "d"},
|
||||
}
|
||||
|
||||
var mapsString = `{` +
|
||||
`"Map":{"A":"b"},` +
|
||||
`"InterfaceMap":{"G":1},` +
|
||||
`"NilMap":null,` +
|
||||
`"CustomMap":{"c":"d"}` +
|
||||
`"CustomMap":{"c":"d"},` +
|
||||
`"CustomMapWithEmptyKey":{"":"d"}` +
|
||||
`}`
|
||||
|
||||
type NamedSlice []Str
|
||||
|
||||
Reference in New Issue
Block a user