找到你要的答案

Q:Serialize class A into class B java

Q:一个java类的序列化为B类

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;
}

所以我知道这可能听起来错/坏,但这是我的情况

无法修改的遗留代码。一类是豆类已序列化JSON是B类C类的一部分,我要上课我要加他为B类为C类。

有什么好方法代替复制构造函数吗?

Class A {

    String a;
    String b;
}

Class B {

    String a;
    String b;
}

Class C {
    ..
    ..
    ..
    B b;
}
answer1: 回答1:

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. http://stackoverflow.com/a/3916282/1129313

你可能想尝试这个,在这里你需要扩展对象输入流和使用它来读取序列化的文件。您可以指定新的类,你要反序列化。http://stackoverflow.com/a/3916282/1129313

java  serialization