Java Utililty Methods Object Serialize

List of utility methods to do Object Serialize

Description

The list of methods to do Object Serialize are organized into topic(s).

Method

voidserialize(Object obj, String fname, boolean gzipped)
serialize
serialize(obj, new File(fname), gzipped);
Stringserialize(Object objData, Class typeOfT)
serialize
String output;
if (objData == null) {
    return null;
ObjectMapper mapper = new ObjectMapper();
ByteArrayOutputStream os = new ByteArrayOutputStream();
mapper.writeValue(os, typeOfT);
output = new String(os.toByteArray(), "UTF-8");
...
byte[]Serialize(Object object)
Serialize a object
ByteArrayOutputStream byteStream;
ObjectOutput output;
byte[] objectBytes;
byteStream = new ByteArrayOutputStream();
output = new ObjectOutputStream(byteStream);
output.writeObject(object);
output.close();
objectBytes = byteStream.toByteArray();
...
byte[]serialize(Object object)
serialize
return convertObjectToBytes(object);
byte[]serialize(Object object)
serialize
ObjectOutputStream oos = null;
ByteArrayOutputStream baos = null;
try {
    baos = new ByteArrayOutputStream();
    oos = new ObjectOutputStream(baos);
    oos.writeObject(object);
    byte[] bytes = baos.toByteArray();
    return bytes;
...
byte[]serialize(Object object)
serialize
ByteArrayOutputStream baos = null;
BufferedOutputStream bos = null;
ObjectOutputStream oos = null;
try {
    baos = new ByteArrayOutputStream();
    bos = new BufferedOutputStream(bos);
    oos = new ObjectOutputStream(bos);
    oos.writeObject(object);
...
byte[]serialize(Object object)
serialize
try (ByteArrayOutputStream buffer = new ByteArrayOutputStream(4096)) {
    try (ObjectOutputStream output = new ObjectOutputStream(buffer)) {
        output.writeObject(object);
    return buffer.toByteArray();
} catch (IOException e) {
    throw new RuntimeException(e);
Stringserialize(Object object)
serialize
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos)) {
    oos.writeObject(object);
    oos.flush();
    byte bytes[] = baos.toByteArray();
    return Base64.getEncoder().encodeToString(bytes);
byte[]serialize(Object object)
serialize
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
    objectOutputStream.writeObject(object);
    objectOutputStream.flush();
    return byteArrayOutputStream.toByteArray();
byte[]serialize(Object object)
serialize
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream objectOut = new ObjectOutputStream(byteOut);
objectOut.writeObject(object);
objectOut.close();
return byteOut.toByteArray();