mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
invalid_indirect_of_pointer_on_array fix invalid indirect of a pointer on a array
This commit is contained in:
+3
-3
@@ -51,7 +51,7 @@ var primitiveStringDecoders = map[reflect.Kind]string{
|
||||
}
|
||||
|
||||
var customDecoders = map[string]string{
|
||||
"json.Number": "in.JsonNumber()",
|
||||
"json.Number": "in.JsonNumber()",
|
||||
}
|
||||
|
||||
// genTypeDecoder generates decoding code for the type t, but uses unmarshaler interface if implemented by t.
|
||||
@@ -88,7 +88,7 @@ func (g *Generator) genTypeDecoder(t reflect.Type, out string, tags fieldTags, i
|
||||
func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags fieldTags, indent int) error {
|
||||
ws := strings.Repeat(" ", indent)
|
||||
// Check whether type is primitive, needs to be done after interface check.
|
||||
if dec := customDecoders[t.String()]; dec != "" {
|
||||
if dec := customDecoders[t.String()]; dec != "" {
|
||||
fmt.Fprintln(g.out, ws+out+" = "+dec)
|
||||
return nil
|
||||
} else if dec := primitiveStringDecoders[t.Kind()]; dec != "" && tags.asString {
|
||||
@@ -170,7 +170,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
|
||||
fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') {")
|
||||
fmt.Fprintln(g.out, ws+" if "+iterVar+" < "+fmt.Sprint(length)+" {")
|
||||
|
||||
if err := g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+3); err != nil {
|
||||
if err := g.genTypeDecoder(elem, "("+out+")["+iterVar+"]", tags, indent+3); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT
|
||||
fmt.Fprintln(g.out, ws+" out.RawByte(',')")
|
||||
fmt.Fprintln(g.out, ws+" }")
|
||||
|
||||
if err := g.genTypeEncoder(elem, in+"["+iVar+"]", tags, indent+1, false); err != nil {
|
||||
if err := g.genTypeEncoder(elem, "("+in+")["+iVar+"]", tags, indent+1, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ var testCases = []struct {
|
||||
{&mapUint64StringValue, mapUint64StringValueString},
|
||||
{&mapUintptrStringValue, mapUintptrStringValueString},
|
||||
{&intKeyedMapStructValue, intKeyedMapStructValueString},
|
||||
{&intArrayStructValue, intArrayStructValueString},
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
|
||||
@@ -757,3 +757,21 @@ var intKeyedMapStructValueString = `{` +
|
||||
`"foo":{"42":"life"},` +
|
||||
`"bar":{"32":{"354634382":"life"}}` +
|
||||
`}`
|
||||
|
||||
type IntArray [2]int
|
||||
|
||||
//easyjson:json
|
||||
type IntArrayStruct struct {
|
||||
Pointer *IntArray `json:"pointer"`
|
||||
Value IntArray `json:"value"`
|
||||
}
|
||||
|
||||
var intArrayStructValue = IntArrayStruct{
|
||||
Pointer: &IntArray{1, 2},
|
||||
Value: IntArray{1, 2},
|
||||
}
|
||||
|
||||
var intArrayStructValueString = `{` +
|
||||
`"pointer":[1,2],` +
|
||||
`"value":[1,2]` +
|
||||
`}`
|
||||
|
||||
Reference in New Issue
Block a user