Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:26:20+00:00 2026-06-15T05:26:20+00:00

I’m trying to serialize and de-serialize a Bouncy Castle X509CertificateObject using org.apache.commons.lang3.SerializationUtils . Apparently

  • 0

I’m trying to serialize and de-serialize a Bouncy Castle X509CertificateObject using org.apache.commons.lang3.SerializationUtils.
Apparently the de-serialized object is of a different type (sun.security.x509.X509CertImpl) than the originally serialized object (org.bouncycastle.jce.provider.X509CertificateObject). Consequently casting fails.
What am I doing wrong?

public static void test(X509CertificateObject certObj) {
    byte[] serializedObj;
    Object deSerializedObj;
    X509CertificateObject deSerializedCertObj;
    X509Certificate deSerializedCert;

    System.out.println("certObj type: " + certObj.getClass().getName());
    serializedObj = SerializationUtils.serialize(certObj);
    deSerializedObj = SerializationUtils.deserialize(serializedObj);
    System.out.println("deSerializedObj type: " + deSerializedObj.getClass().getName());
    deSerializedCert = (X509Certificate) deSerializedObj;
    System.out.println("deSerializedCert type: " + deSerializedCert.getClass().getName());
    deSerializedCertObj = (X509CertificateObject) deSerializedObj;
    System.out.println("deSerializedCertObj type: " + deSerializedCertObj.getClass().getName());
}

results in:

certObj type: org.bouncycastle.jce.provider.X509CertificateObject
deSerializedObj type: sun.security.x509.X509CertImpl
deSerializedCert type: sun.security.x509.X509CertImpl

and finally in

java.lang.ClassCastException: sun.security.x509.X509CertImpl cannot be cast to org.bouncycastle.jce.provider.X509CertificateObject
at Test.test(Test.java:1010)
at Test.main(Test.java:153)

Is this because the upper class of X509CertificateObject, which is X509Certificate, is abstract and/or because X509CertificateObject does not define its own serialVersionUID?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:26:21+00:00Added an answer on June 15, 2026 at 5:26 am

    I finally found a workaround/solution.
    The Java serialization problem seems to be due to a conflict between BC and Java JCE.
    I’m now using XStream in connection with Apache Commons Codec:

    import org.apache.commons.codec.binary.StringUtils;
    import com.thoughtworks.xstream.XStream;
    
    public static byte[] serializeToXML(Object obj, XStream xStreamConfig)
        throws Exception
    {
        XStream xstream;
        String certObjString;
        byte[] certObjByte;
    
        if(xStreamConfig == null) {
            xstream = new XStream();
        } else {
            xstream = xStreamConfig;
        }
    
        certObjString = xstream.toXML(obj);
    
        certObjByte = StringUtils.getBytesUtf8(certObjString);
    
        return certObjByte;
    }
    
    public static Object deserializeFromXML(byte[] objectByteArray, XStream xStreamConfig)
    {
        String objectString;
        Object object;
        XStream xstream;
    
        if(xStreamConfig == null) {
            xstream = new XStream();
        } else {
            xstream = xStreamConfig;
        }
    
        objectString = StringUtils.newStringUtf8(objectByteArray);
    
        object = xstream.fromXML(objectString);
    
        return object;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.