Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Serialize only superclass

I have the following classes:

class A implements Serializable {
  String field1;
  String field2;
  // a lot more fields here...
}

class B extends A {
  int someOtherField;
}

where B is my class and A is in a package I don't own. In my environment, an object of class B is serialized and will later be deserialized in a different environment, where only class A is in the classpath and not class B, thus an error will occur, that class B is not found.

To solve this problem, I could add a copy constructor to A as follows and instead of serializing an object b, I would serialize new A(b):

A(A other) {
  this.field1 = other.field1;
  this.field1 = other.field1;
  // and so on
}

My problem now is that I can only change B, but not A. So, is there any way I can serialize a B and deserialize it as an A without access to the source code of A?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!