[java] How to serialize an object into a string