-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
https://go.dev/play/p/uV8Vr7trqBv
https://pkg.go.dev/encoding#TextUnmarshaler says:
UnmarshalText must be able to decode the form generated by MarshalText.
MarshalText clearly supports a nil *big.Int value, marshaling it as <nil>, but UnmarshalText rejects it. I think this goes against the TextUnmarshaler docs.
I'm not arguing that marshaling and unmarshaling a nil big int makes any sense, for what it's worth. Just that I always assumed, like the docs say, that roundtripping a value via marshal and then unmarshal was a safe thing to do. If marshaling allows for a nil pointer, unmarshal should support it too - although I'm not sure what it could possibly do, given that it can't set a *big.Int receiver to nil. Perhaps set it to its zero value?
Note that MarshalJSON and UnmarshalJSON don't have this problem. They both support null, and the unmarshal is simply a no-op. Presumably we could do the same in UnmarshalText.