• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert object into string or text like ascii etc without losing object persistence

 
shaharyar khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks, i want to know that how can we convert an object of any class into string without losing data.Actually i want to store a object into relational database where as that database only takes ascii or string format.So how can i store my object to that database so that i can get back without losing persistence of that object.thanks
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well champ, I'd say that that wouldn't be effective. What you can do is serialize your object, and then you wouldn't store it in the database as a String, but instead, you would physically store it as a regular file. And also, instead of retrieving your object from a database, you would deserialize it from this file. I think this would do what you are looking for.

Here's a good article to get you started: Discover the secrets of the Java Serialization API.
 
shaharyar khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forget about to store in database.just tell me how can i convert it into ascii or string and then get back even from maps.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you don't want to build special support for each class, the most obvious way is to first serialize the object to a byte[] using a combination of ByteArrayOutputStream and ObjectOutputStream, then Base64 encode that byte[] into a String. Don't create a String directly from the byte[] because it will contain several "characters" that shouldn't go in Strings.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic