如何编组&;是否将x509.Certificate解组到JSON或从JSON解组?

如何编组&;是否将x509.Certificate解组到JSON或从JSON解组?,json,go,ssl-certificate,x509,Json,Go,Ssl Certificate,X509,我有一个类似这样的结构,其中PrivateKey和PublicKey是自己的类型,映射到[]byte: type Secret struct { Cert *x509.Certificate ValidFor string Private PrivateKey Public PublicKey } 此结构作为字段嵌入到另一个结构中,该结构被封送到JSON中。编组外部结构似乎工作正常,JSON看起来正常,但是解编组似乎会导致以下错误: json:

我有一个类似这样的结构,其中PrivateKey和PublicKey是自己的类型,映射到
[]byte

type Secret struct {
    Cert     *x509.Certificate
    ValidFor string
    Private  PrivateKey
    Public   PublicKey
}

此结构作为字段嵌入到另一个结构中,该结构被封送到JSON中。编组外部结构似乎工作正常,JSON看起来正常,但是解编组似乎会导致以下错误:

json: cannot unmarshal number json: cannot unmarshal number 54368953042[...number shortened...] into Go struct field Certificate.Secrets.Cert.PublicKey of type float64
显然,解组器似乎被包含公钥的big.int绊倒了。现在,我在网上找到了一个解决方案,但是考虑到我的结构有点嵌套,这似乎是一个详尽的解决方案


现在我想知道,有没有更简单的方法来封送和解封包含big.int的x509.Certificate?还是手动存储、替换和恢复有问题字段的最佳方法?

您可以使用主要基于64的pem:让您的
*Key
类型以任何您喜欢的方式实现并序列化这些数字。