public static String toJson ( Object obj ) { StringWriter sw = new StringWriter ( ) ; ObjectMapper mapper = getDefaultObjectMapper ( ) ; try { JsonGenerator jg = mapper . getFactory ( ) . createGenerator ( sw ) ; mapper . writeValue ( jg , obj ) ; } catch ( JsonMappingException e ) { e . printStackTrace ( ) ; } catch ( JsonGenerationException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return sw . toString ( ) ; }
Convert object to json . If object contains fields of type date they will be converted to strings using lightblue date format .