public static void serializeAsStream(Object o, OutputStream s) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            Map<String, Object> config = new HashMap<String, Object>();
            config.put(JsonGenerator.PRETTY_PRINTING, true);
            JsonWriterFactory writerFactory = Json.createWriterFactory(config);
            JsonWriter streamWriter = writerFactory.createWriter(s);
            streamWriter.write(builtJsonObject);
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
public static void serializeAsStream ( Object o , OutputStream s ) throws IOException { try { JsonStructure builtJsonObject = findFieldsToSerialize ( o ) . mainObject ; Map < String , Object > config = new HashMap < String , Object > ( ) ; config . put ( JsonGenerator . PRETTY_PRINTING , true ) ; JsonWriterFactory writerFactory = Json . createWriterFactory ( config ) ; JsonWriter streamWriter = writerFactory . createWriter ( s ) ; streamWriter . write ( builtJsonObject ) ; } catch ( IllegalStateException ise ) { throw new IOException ( "Unable to build JSON for Object" , ise ) ; } catch ( JsonException e ) { throw new IOException ( "Unable to build JSON for Object" , e ) ; } }
Convert a POJO into Serialized JSON form.

@param o the POJO to serialize
@param s the OutputStream to write to..
@throws IOException when there are problems creating the JSON.