samedi 27 octobre 2018

Java convert Object to String and then to Object again

Let p be an instance of any class C.

My goal is to build 2 functions:

String objectToString(Object o){...}
Object stringToObject(String s){...}

String s = objectToString(p) must convert p to a String s (so it is easier to store in the memory for my application).

Then, when I retrieve s from the memory, C p2 = (C) stringToObject(s) should parse it to an instance p2 of C that will look exactly like p.

The way the String looks doesn't matter, as long as it becomes p again, for any C.

How can I build such functions?





Aucun commentaire:

Enregistrer un commentaire