@SuppressWarnings({"NonSerializableObjectPassedToObjectStream", "ThrowFromFinallyBlock"}) @Override public <T> SerializedObject<T> serialize(Object instance, Class<T> expectedType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); try { oos.writeObject(instance); } finally { oos.flush(); } } catch (IOException e) { throw new SerializationException("An exception occurred writing serialized data to the output stream", e); } T converted = converter.convert(baos.toByteArray(), expectedType); return new SimpleSerializedObject<>(converted, expectedType, getSerializedType(instance)); }
@SuppressWarnings({"NonSerializableObjectPassedToObjectStream", "ThrowFromFinallyBlock"}) @Override public <T> SerializedObject<T> serialize(Object instance, Class<T> expectedType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); try { oos.writeObject(instance); } finally { oos.flush(); } } catch (IOException e) { throw new SerializationException("An exception occurred writing serialized data to the output stream", e); } T converted = converter.convert(baos.toByteArray(), expectedType); return new SimpleSerializedObject<>(converted, expectedType, getSerializedType(instance)); }
@SuppressWarnings({"NonSerializableObjectPassedToObjectStream", "ThrowFromFinallyBlock"}) @Override public <T> SerializedObject<T> serialize(Object instance, Class<T> expectedType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); try { oos.writeObject(instance); } finally { oos.flush(); } } catch (IOException e) { throw new SerializationException("An exception occurred writing serialized data to the output stream", e); } T converted = converter.convert(baos.toByteArray(), expectedType); return new SimpleSerializedObject<>(converted, expectedType, getSerializedType(instance)); }