• Post Reply Bookmark Topic Watch Topic
  • New Topic

object string representation  RSS feed

 
ethem narman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to have string representations of different objects and I will use these strings to store my objects as base64 encoded bytes.
What I like to learn is if I have something like this:

Class1 a = new Class1();
String str = String.valueOf(a);

then how can I convert this str to Class1 object back.

As I know Object.toString() method gives
getClass().getName() + '@' + Integer.toHexString(hashCode())
and this is the string I will have if I do not write my own toString method.

I just want to have my object back from this string.
Is there a way for that?
Thanks.

aysan
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java supports object serialization, a method to write an object to a stream. All you have to do is base64 encode that stream and you are set.
You can also serialize objects to xml, which may be easier depending on your requirements.
 
ethem narman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe.
I guess, either of them will solve my problem.

aysan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!