Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda