mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #158 from regeda/invalid_indirect_of_pointer_on_array
fix invalid indirect of a pointer on a array
This commit is contained in:
+1
-1
@@ -180,7 +180,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
@@ -175,7 +175,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
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ var testCases = []struct {
|
||||
{&mapUint64StringValue, mapUint64StringValueString},
|
||||
{&mapUintptrStringValue, mapUintptrStringValueString},
|
||||
{&intKeyedMapStructValue, intKeyedMapStructValueString},
|
||||
{&intArrayStructValue, intArrayStructValueString},
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
|
||||
@@ -766,3 +766,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