How to deserialize object to new object with the same name?

Zephyr

I have an application that previously stored some data by serializing the model object (QuickNote). This was then loaded by deserialization.

However, I am updating the application to store the data by XML instead and I need to be able to import the old, serialized object for conversion. The new object, which does not implement Serializable, also has the same name though.(QuickNote).

I am trying to deserialize the old QuickNote and store it into the new one using the follow code:

FileInputStream fileIn = new FileInputStream("data/quicknotes_user.dat");
ObjectInputStream in = new ObjectInputStream(fileIn);
List<OldQuickNote> newList = (List<OldQuickNote>) in.readObject();

Since the class name for the old serialized file is QuickNote, I get the error java.io.InvalidClassException: model.QuickNote; class invalid for deserialization due to the new class having the same name and not implementing Serializable.

Is there a way to deserialize this QuickNote object into an OldQuickNote object? Both QuickNote and OldQuickNote are identical except that QuickNote no longer implements Serializable but OldQuickNote does.

I did try to search for answers, but to be honest, I am not even sure how to search for this as I obviously made a poor design decision when electing to serialize the QuickNote object in the first place.

Caveats:

  1. I cannot change the object type (class name) for the serialized object as it is now residing on the user's systems.
  2. The new QuickNote object cannot be changed to implement Serializable because it is annotated and used for JAXB marshalling.
Zephyr

This was answered in the comments but the one with the answer didn't post it as such.

I ended up moving the old class to a different package and converted the class when the user ran the program again.

All I had to do then was wait for my users to all update the the new version and deleted the old class.

Thank you!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Deserialize into object with variable name

From Dev

How to add new property with same key name inside declared object?

From Dev

Deserialize Xml Using Same Object With Different Element Name

From Dev

How to deserialize XML into an object?

From Dev

How to Deserialize the current object

From Dev

How to deserialize XML into an object?

From Dev

How to deserialize JSON with duplicate property names in the same object

From Dev

New object with name in variable

From Dev

How do I check if an object is equal to a new object of the same class?

From Dev

How do I check if an object is equal to a new object of the same class?

From Dev

How to deserialize JSON to a Swift object?

From Dev

How to deserialize json string into object

From Dev

how to deserialize XML to List<Object>

From Dev

How to deserialize json string into object

From Dev

How to deserialize inner XML to an object?

From Dev

How to deserialize an object with an object as it's value

From Dev

XML deserialize to same object different element names

From Dev

An Object with a Same Name as the Class in Java

From Dev

How do I deserialize json to c# model if the json object has a name starting with an int

From Dev

Using the same Reference for a new object

From Dev

How let the Json.net return a new T value when the Deserialize Object is null?

From Dev

How can I declare same object name for different class?

From Dev

How to sort an array of names, relevant to the value of an integer in the same object as the name?

From Dev

How can I add multiple properties with the same name to an object?

From Dev

How do I convert a string to an new object's name?

From Dev

How to name method used by __init__ to determine value of new object?

From Dev

How to deserialize a JSON HashMap<String, Object>?

From Dev

How to deserialize bytes back to my class object?

From Dev

How to deserialize list of object json by NewtonSoft?

Related Related

  1. 1

    Deserialize into object with variable name

  2. 2

    How to add new property with same key name inside declared object?

  3. 3

    Deserialize Xml Using Same Object With Different Element Name

  4. 4

    How to deserialize XML into an object?

  5. 5

    How to Deserialize the current object

  6. 6

    How to deserialize XML into an object?

  7. 7

    How to deserialize JSON with duplicate property names in the same object

  8. 8

    New object with name in variable

  9. 9

    How do I check if an object is equal to a new object of the same class?

  10. 10

    How do I check if an object is equal to a new object of the same class?

  11. 11

    How to deserialize JSON to a Swift object?

  12. 12

    How to deserialize json string into object

  13. 13

    how to deserialize XML to List<Object>

  14. 14

    How to deserialize json string into object

  15. 15

    How to deserialize inner XML to an object?

  16. 16

    How to deserialize an object with an object as it's value

  17. 17

    XML deserialize to same object different element names

  18. 18

    An Object with a Same Name as the Class in Java

  19. 19

    How do I deserialize json to c# model if the json object has a name starting with an int

  20. 20

    Using the same Reference for a new object

  21. 21

    How let the Json.net return a new T value when the Deserialize Object is null?

  22. 22

    How can I declare same object name for different class?

  23. 23

    How to sort an array of names, relevant to the value of an integer in the same object as the name?

  24. 24

    How can I add multiple properties with the same name to an object?

  25. 25

    How do I convert a string to an new object's name?

  26. 26

    How to name method used by __init__ to determine value of new object?

  27. 27

    How to deserialize a JSON HashMap<String, Object>?

  28. 28

    How to deserialize bytes back to my class object?

  29. 29

    How to deserialize list of object json by NewtonSoft?

HotTag

Archive