diff --git a/Makefile b/Makefile index 7cfec87..18c6687 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,8 @@ generate: root build .root/src/$(PKG)/tests/nothing.go \ .root/src/$(PKG)/tests/named_type.go \ .root/src/$(PKG)/tests/custom_map_key_type.go \ - .root/src/$(PKG)/tests/embedded_type.go + .root/src/$(PKG)/tests/embedded_type.go \ + .root/src/$(PKG)/tests/reference_to_pointer.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go @@ -37,6 +38,7 @@ generate: root build .root/bin/easyjson .root/src/$(PKG)/tests/named_type.go .root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go .root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go + .root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go .root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go test: generate root diff --git a/gen/decoder.go b/gen/decoder.go index 606602f..d89dd31 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -198,7 +198,12 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field dec := g.getDecoderName(t) g.addType(t) - fmt.Fprintln(g.out, ws+dec+"(in, &"+out+")") + if len(out) > 0 && out[0] == '*' { + // NOTE: In order to remove an extra reference to a pointer + fmt.Fprintln(g.out, ws+dec+"(in, "+out[1:]+")") + } else { + fmt.Fprintln(g.out, ws+dec+"(in, &"+out+")") + } case reflect.Ptr: fmt.Fprintln(g.out, ws+"if in.IsNull() {") diff --git a/tests/reference_to_pointer.go b/tests/reference_to_pointer.go new file mode 100644 index 0000000..6768e53 --- /dev/null +++ b/tests/reference_to_pointer.go @@ -0,0 +1,10 @@ +package tests + +type Struct1 struct { +} + +//easyjson:json +type Struct2 struct { + From *Struct1 `json:"from,omitempty"` + Through *Struct1 `json:"through,omitempty"` +}