You can use an ObjectOutputStream to "capture" these objects in an array of bytes and send them to an OutputStream.
String s = "test";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( s );
byte[] byteArray = baos.toByteArray();
for ( byte b : byteArray ) {
System.out.print( (char) b );
}
Another non-general option would be to serialize the object in a lowercase representation, for example. Csv
source
share