private static String jsonEncode ( Object object ) throws IOException { ObjectMapper mapper = new ObjectMapper ( ) ; ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; try { mapper . writeValue ( outputStream , object ) ; return new String ( outputStream . toByteArray ( ) ) ; } catch ( JsonGenerationException e ) { logger . severe ( "unable encode" ) ; throw new IOException ( e ) ; } catch ( JsonMappingException e ) { logger . severe ( "unable encode" ) ; throw new IOException ( e . getMessage ( ) ) ; } }
Encode a java object into a json which is returned as a string