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

  • SEARCH
  • Home
  • 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 4052172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:17:13+00:00 2026-05-20T14:17:13+00:00

I have a Java class that is stored in an HttpSession object that’s serialized

  • 0

I have a Java class that is stored in an HttpSession object that’s serialized and transfered between servers in a cluster environment. For the purpose of this explanation, lets call this class “Person”.

While in the process of improving the code, this class was moved from “com.acme.Person” to “com.acme.entity.Person”. Internally, the class remains exactly the same (same fields, same methods, same everything).

The problem is that we have two sets of servers running the old code and the new code at the same time.
The servers with the old code have serialized HttpSession object and when the new code unserializes it, it throws a ClassNotFoundException because it can’t find the old reference to com.acme.Person. At this point, it’s easy to deal with this because we can just recreate the object using the new package. The problem then becomes that the HttpSession in the new servers, will serialize the object with the new reference to com.acme.entity.Person, and when this is unserialized in the servers running the old code, another exception will be thrown. At this point, we can’t deal with this exception anymore.

What’s the best strategy to follow for this kind of cases?
Is there a way to tell the new servers to serialize the object with the reference to the old package and unserialize references to the old package to the new one?
How would we transition to using the new package and forgetting about the old one once all servers run the new code?

  • 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-05-20T14:17:13+00:00Added an answer on May 20, 2026 at 2:17 pm

    I found this blog post that claims to have a solution, though it doesn’t spell it out very clearly.

    What it is actually saying is that you create a subclass of ObjectInputStream that overrides the readClassDescriptor method to do something like this:

    @Override
    protected java.io.ObjectStreamClass readClassDescriptor() 
            throws IOException, ClassNotFoundException {
        ObjectStreamClass desc = super.readClassDescriptor();
        if (desc.getName().equals("oldpkg.Widget")) {
            return ObjectStreamClass.lookup(newpkg.Widget.class);
        }
        return desc;
    };
    

    You should also look at this SO question and its answers which cover some of the same ground as your question.

    My advice would be: don’t support the case where old versions of software read data serialized by the new version.

    • This is a good opportunity to encourage (actually force) people to upgrade to the latest version of the code-base. Generally speaking, it is in everyone’s interest that this happen sooner rather than later.

    • If it is premature to force people to upgrade for other reasons, then (IMO) you should seriously consider backing out your changes to the class / package names. Wait until you’ve got a clear strategy / plan for upgrading that is 1) technically sound, and 2) acceptable to all stakeholders.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Java class that I need to serialize to be stored
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
I'm currently working on Mangler's Android implementation. I have a java class that looks
I have a simple Java class that has some methods: public class Utils {
I have a Java class MyPojo that I am interested in deserializing from JSON.
I have a quite huge Java class that has several imported packages and libraries
In Java I have the necessity of implementing a class that extends Thread within
I am new to Java. I just read that class variables in Java have
In Java, how can I have a Runnable class that, depending on its constructor,
I'm using Java. I want to have a setter method of one class that

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.