Open chriskaly opened 4 years ago
Change https://golang.org/cl/234017 mentions this issue: encoding/asn1: respect omitempty when marshaling nil values
For anyone who encounters this problem: As a workaround, you can test if the corresponding interface field is nil before marshaling and assign []byte(nil)
to it.
/cc @FiloSottile @agl
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?
asn1.Marshal
a struct containing anil
interface withomitempty
tag. https://play.golang.org/p/x-hrKEJH0FeWhat did you expect to see?
No error and the corresponding field should be omitted from the output. It works with nil slices (see example).
What did you see instead?
Error:
asn1: cannot marshal nil value