USer22999299
USer22999299

Reputation: 5674

Serialize class A into class B java

So i know it might sound wrong / bad but this is the situation i have

legacy code that cannot be modified. class A it is a bean class that has been serialize from JSON class B is part of class C, i'm getting class A and i need to add him as class B into class C.

Is there any good way instead of using copy constructor ?

Class A {

    String a;
    String b;
}

Class B {

    String a;
    String b;
}

Class C {
    ..
    ..
    ..
    B b;
}

Upvotes: 3

Views: 147

Answers (1)

Garry
Garry

Reputation: 4533

you may want to try this, here you need to extend the ObjectInputStream and use it to read the serialized file. you can specify the new class into which you wan to deserialize. https://stackoverflow.com/a/3916282/1129313

Upvotes: 2

Related Questions