Careful! Not compatible with above method to convert objects to byte arrays!
321376
public static <T> T readObject(Class<T> _class, InputStream inputStream) {
        try {
            return defaultObjectMapper.readValue(inputStream, _class);
        } catch (IOException exp) {
            throw new RuntimeException("Failed to read object from inputstream", exp);
        }
    }
1175318
@Override
    public byte[] toBytes(Object object)
    {
        if (object == null)
        {
            return null;
        }

        BigDecimal b = (BigDecimal) object;
        final int scale = b.scale();
        final BigInteger unscaled = b.unscaledValue();
        final byte[] value = unscaled.toByteArray();
        final byte[] bytes = new byte[value.length + 4];
        bytes[0] = (byte) (scale >>> 24);
        bytes[1] = (byte) (scale >>> 16);
        bytes[2] = (byte) (scale >>> 8);
        bytes[3] = (byte) (scale >>> 0);
        System.arraycopy(value, 0, bytes, 4, value.length);
        return bytes;
    }
870275
public static byte[] toByteArrayFst(final Object obj, final ClassLoader classLoader) {
        if (obj == null) {
            return null;
        }
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            FSTConfiguration conf = fstConf.get();
            conf.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
            return conf.asByteArray(obj);
        } catch (Exception e) {
            throw e instanceof SerializationException ? (SerializationException) e
                    : new SerializationException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }
369644
public static byte[] serialize(Serializable obj, boolean gzipOnSerialize) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out;
            if (gzipOnSerialize) { 
                out = new ObjectOutputStream(new GZIPOutputStream(baos));
            } else {
                out = new ObjectOutputStream(baos);
            }
            out.writeObject(obj);
            out.flush();
            out.close();
            return baos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
1043968
public static byte[] getBytes(Object o)
    {
        if (o != null)
        {
            return getBytes(o, o.getClass());
        }

        return null;
    }
610343
private static Object[] convertToObjectArray(Object obj) {
        if (obj instanceof Object[]) {
            return (Object[]) obj;
        }
        int arrayLength = Array.getLength(obj);
        Object[] retArray = new Object[arrayLength];
        for (int i = 0; i < arrayLength; ++i){
            retArray[i] = Array.get(obj, i);
        }
        return retArray;
    }
1063380
@Override
    public Float fromBytes(Class targetClass, byte[] data)
    {
        if (data == null || data.length != 4)
            return (float) 0x0;

        return Float.intBitsToFloat(toInt(data));
    }
797172
@Override
    public final byte[] toBytes(Object val)
    {
        if (val != null)
        {
            Integer value = (Integer) (val);
            return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8),
                    (byte) value.intValue() };
        }
        return null;
    }
1306059
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
    	out.writeByteArray(SerializationTools.toByteArray(error));
    }
1349315
@Override
    public byte[] toBytes(Object object) throws PropertyAccessException
    {
        return object != null ? fromLong(Double.doubleToRawLongBits((Double) object)) : null;
    }
467781
@SuppressWarnings("unchecked")
    public BaseBo fromByteArray(byte[] data) {
        Map<String, Object> dataMap = null;
        try {
            dataMap = data != null ? SerializationUtils.fromByteArray(data, Map.class) : null;
        } catch (Exception e) {
            dataMap = null;
        }
        return fromMap(dataMap);
    }
637794
@Override
  public ByteBuffer toBytes(T object) {
    if (!type.equals(object.getClass())) {
      throw new RuntimeException(
          "The type of the object does not match the parameter type of this marshaller. ");
    }
    Map<String, Object> jsonObject = dataMarshaller.mapFieldNameToValue(object);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      objectMapper.writeValue(out, jsonObject);
      out.write(NEWLINE_CHARACTER.getBytes());
    } catch (IOException e) {
      throw new RuntimeException("Error in serializing to bigquery json " + jsonObject, e);
    }
    return ByteBuffer.wrap(out.toByteArray());
  }
1174827
public byte[] toBytes(T object) {
        try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(stream);
            out.writeObject(object);
            return stream.toByteArray();
        } catch(IOException e) {
            throw new SerializationException(e);
        }
    }
890578
public static byte[] serialize(Object obj, String errorMessage) {
    try {
      return serialize(obj);
    } catch (IOException e) {
      throw new RuntimeException(errorMessage, e);
    }
  }
305341
private byte[] toByteArray(Object val) {
        if (val == null)
            return null;
        if (val instanceof byte[])
            return (byte[]) val;
        if (val instanceof ByteBuffer) {
            // Defensive code but execution should never get here. The internal
            // representation of binary should always be
            // byte[], not ByteBuffer. This allows Item to be converted into
            // a JSON string via Jackson without causing trouble.
            return copyAllBytesFrom((ByteBuffer)val);
        }
        throw new IncompatibleTypeException(val.getClass()
                + " cannot be converted into a byte array");
    }
307857
public static Object getObjectFromBytes(byte[] objBytes) throws Exception {
		if (objBytes == null || objBytes.length == 0) {
			return null;
		}
		ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
		ObjectInputStream oi = new ObjectInputStream(bi);
		return oi.readObject();
	}
418188
public static byte[] objectToBytes(Object object) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(baos);
    os.writeObject(object);
    return baos.toByteArray();
  }