code: public static void writeObject(Object object, OutputStream outputStream) {
          try {
              if (object instanceof Compactable) {
                  ((Compactable) object).compact();
              }
              defaultObjectMapper.writeValue(outputStream, object);
          } catch (IOException exp) {
              throw new RuntimeException("Failed to write object to outputstream", exp);
          }
      }
docs: Careful! Not compatible with above method to convert objects to byte arrays!