public static String objectToJson ( Object item , Map < String , Object > optionalArgs ) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream ( ) ; JsonWriter writer = new JsonWriter ( stream , optionalArgs ) ; writer . write ( item ) ; writer . close ( ) ; return new String ( stream . toByteArray ( ) , "UTF-8" ) ; } catch ( Exception e ) { throw new JsonIoException ( "Unable to convert object to JSON" , e ) ; } }
Convert a Java Object to a JSON String .