Repository: goccy/go-json (go)

Issue:
decode struct with pointer field must be nil when error
![image](https://github.com/goccy/go-json/assets/12197761/c667fdac-c225-4ca2-a355-d91fd77ba7b3)

This is useful when used with go-validator so that it is not validated with its default value

Pull request:
fix: decode struct with pointer must be nil
fix #472 

Patch:
diff --git a/internal/decoder/ptr.go b/internal/decoder/ptr.go
index de12e10..ae22994 100644
--- a/internal/decoder/ptr.go
+++ b/internal/decoder/ptr.go
@@ -85,6 +85,7 @@ func (d *ptrDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.P
 	}
 	c, err := d.dec.Decode(ctx, cursor, depth, newptr)
 	if err != nil {
+		*(*unsafe.Pointer)(p) = nil
 		return 0, err
 	}
 	cursor = c


Test patch:
diff --git a/decode_test.go b/decode_test.go
index df914ed..8f32ced 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -197,6 +197,13 @@ func Test_Decoder(t *testing.T) {
 			assertEq(t, "interface{}", v.F, nil)
 			assertEq(t, "nilfunc", true, v.G == nil)
 		})
+		t.Run("struct.pointer must be nil", func(t *testing.T) {
+			var v struct {
+				A *int
+			}
+			json.Unmarshal([]byte(`{"a": "alpha"}`), &v)
+			assertEq(t, "struct.A", v.A, (*int)(nil))
+		})
 	})
 	t.Run("interface", func(t *testing.T) {
 		t.Run("number", func(t *testing.T) {