JCR-2331: Fix cases where an IOException is thrown while serializing the data