Repository: go
Issue: encoding/json: custom unmarshal not called on empty value with ,string
Labels: NeedsInvestigation

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.17.6 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes.

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/aron/Library/Caches/go-build"
GOENV="/Users/aron/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/aron/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/aron/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8j/pt4fjhkj11d3xd9344pdspmh0000gn/T/go-build3937592509=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

We have incoming JSON that receives a Boolean value as a quoted number. We have a custom `UnmarshalJSON` method that helps parse different types of Boolean values. When that incoming value comes in with an unexpected, empty string value, the unmarshal function is never called; the decoder decides that this situation is an error without giving the target type an opportunity to handle the value.

Perhaps this is an unexpected, unsupported situation? The `,string` documentation indicates that it can be used for Boolean types, but we have added a custom `UnmarshalJSON` to the mix.

This same type has caused us struggles in the past; see https://github.com/golang/go/issues/20651

```go
package main

import (
	"encoding/json"
	"fmt"
	"strconv"
)

type parsedBool bool

func (p *parsedBool) UnmarshalJSON(data []byte) error {
	v, err := strconv.ParseBool(string(data))
	if err != nil {
		return fmt.Errorf("custom error: %w", err)
	}
	*p = parsedBool(v)
	return nil
}

type Target struct {
	Enabled parsedBool `json:"enabled,string"`
}

func main() {
	var err error
        empty := `{"enabled":""}`
        truth := `{"enabled":"t"}`
        unexpected := `{"enabled":"unexpected"}`

	target := Target{}
	err = json.Unmarshal([]byte(empty), &target)
	fmt.Printf("target: %#v; error: %s\n", target, err)
	err = json.Unmarshal([]byte(unexpected), &target)
	fmt.Printf("target: %#v; error: %s\n", target, err)
	err = json.Unmarshal([]byte(truth), &target)
	fmt.Printf("target: %#v; error: %s\n", target, err)
	
}
```

https://play.golang.com/p/bFAQ4Xu6mar

### What did you expect to see?

Expected to see `parsedBool#UnmarshalJSON` attempt parse the incoming value, producing something like:

```default
target: main.Target{Enabled:false}; error: custom error: strconv.ParseBool: parsing "": invalid syntax
target: main.Target{Enabled:false}; error: custom error: strconv.ParseBool: parsing "unexpected": invalid syntax
target: main.Target{Enabled:true}; error: %!s(<nil>)
```

### What did you see instead?

An error about an invalid `,string` struct tag, which prevents the call to `UnmarshalJSON`.

```default
target: main.Target{Enabled:false}; error: json: invalid use of ,string struct tag, trying to unmarshal "" into main.parsedBool
target: main.Target{Enabled:false}; error: custom error: strconv.ParseBool: parsing "unexpected": invalid syntax
target: main.Target{Enabled:true}; error: %!s(<nil>)
```