encoding/json: custom unmarshal not called on empty value with ,string #50997
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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 customUnmarshalJSON
to the mix.This same type has caused us struggles in the past; see #20651
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:What did you see instead?
An error about an invalid
,string
struct tag, which prevents the call toUnmarshalJSON
.The text was updated successfully, but these errors were encountered: