public static int serialize ( OutputStream stream , Object obj ) { ObjectMapper mapper = createMapperWithJaxbAnnotationInspector ( ) ; try ( DataOutputStream data = new DataOutputStream ( stream ) ; OutputStreamWriter writer = new OutputStreamWriter ( data , StandardCharsets . UTF_8 ) ) { mapper . writerWithDefaultPrettyPrinter ( ) . writeValue ( writer , obj ) ; return data . size ( ) ; } catch ( IOException e ) { throw new ReportGenerationException ( e ) ; } }
Serialize specified object to directory with specified name . Given output stream will be closed .