javax.xml.bind.JAXBException: class XXXX nor any of its super class is known to this context
[javax.xml.bind.JAXBException: class org.bouncycastle.jcajce.provider.asymmetric.x509.X509CRLObject nor any of its super class is known to this context.] at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317) at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243) at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110) at xades4j.xml.marshalling.BaseJAXBMarshaller.doJAXBMarshalling(BaseJAXBMarshaller.java:180) ... 30 more Caused by: javax.xml.bind.JAXBException: class org.bouncycastle.jcajce.provider.asymmetric.x509.X509CRLObject nor any of its super class is known to this context. at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:214) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:229) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:621) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:154) at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141) at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:146) at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:116) at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:304) at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:311) at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:61) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462) at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314) ... 33 more Caused by: javax.xml.bind.JAXBException: class org.bouncycastle.jcajce.provider.asymmetric.x509.X509CRLObject nor any of its super class is known to this context. at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:554) at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:616) ... 57 more
本例中 X509CRLObject 和 EncapsulatedPKIDataType 混淆了,xml 文件中只允许使用后者。其他元素属性同理。
crl互转
//X509CRL -> XmlEncapsulatedPKIDataType XmlEncapsulatedPKIDataType xmlEncapsulatedPKIDataType = new XmlEncapsulatedPKIDataType(); xmlEncapsulatedPKIDataType.setValue(crl.getEncoded()); //XmlEncapsulatedPKIDataType -> X509CRL CertificateFactory factory = CertificateFactory.getInstance("X509"); byte[] value = xmlEncapsulatedPKIDataType.getValue(); CRL gCRL = factory.generateCRL(new ByteArrayInputStream(value)); X509CRL crl = (X509CRL)gCRL;
cer互转
//X509Certificate -> XmlEncapsulatedPKIDataType XmlEncapsulatedPKIDataType xmlEncapsulatedPKIDataType = new XmlEncapsulatedPKIDataType(); xmlEncapsulatedPKIDataType.setValue(cer.getEncoded()); //XmlEncapsulatedPKIDataType -> X509Certificate CertificateFactory factory = CertificateFactory.getInstance("X509"); byte[] value = xmlEncapsulatedPKIDataType.getValue(); Certificate gCertificate = factory.generateCertificate(new ByteArrayInputStream(value)); X509Certificate cer = (X509Certificate)gCertificate;