public static String toJsonString(Object val, boolean pretty) {
        try {
            return pretty ? mapper.writerWithDefaultPrettyPrinter().with(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS).writeValueAsString(val) : mapper.writeValueAsString(val);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public static String toJsonString ( Object val , boolean pretty ) { try { return pretty ? mapper . writerWithDefaultPrettyPrinter ( ) . with ( SerializationFeature . ORDER_MAP_ENTRIES_BY_KEYS ) . writeValueAsString ( val ) : mapper . writeValueAsString ( val ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Convert Java object to a JSON string.

@param val Java object
@param pretty enable/disable pretty print
@return JSON string.