src/main/java/com/arpnetworking/logback/serialization/steno/SafeSerializationHelper.java
static void safeEncodeThrowable(final StringBuilder encoder, final Throwable throwable) {
        encoder.append("{\"type\":\"")
                .append(throwable.getClass().getName())
                .append("\",\"message\":");
        safeEncodeValue(encoder, throwable.getMessage());
        encoder.append(",\"backtrace\":[");
        for (final StackTraceElement ste : throwable.getStackTrace()) {
            safeEncodeValue(encoder, ste.toString());
            encoder.append(",");
        }
        if (throwable.getStackTrace().length == 0) {
            encoder.append("]");
        } else {
            encoder.setCharAt(encoder.length() - 1, ']');
        }
        encoder.append(",\"data\":{");
        if (throwable.getSuppressed().length > 0) {
            encoder.append("\"suppressed\":[");
            for (final Throwable suppressed : throwable.getSuppressed()) {
                safeEncodeThrowable(encoder, suppressed);
                encoder.append(",");
            }
            encoder.setCharAt(encoder.length() - 1, ']');
            encoder.append(",");
        }
        if (throwable.getCause() != null) {
            encoder.append("\"cause\":");
            safeEncodeThrowable(encoder, throwable.getCause());
            encoder.append(",");
        }
        if (encoder.charAt(encoder.length() - 1) == ',') {
            encoder.setCharAt(encoder.length() - 1, '}');
        } else {
            encoder.append("}");
        }
        encoder.append("}");
    }
static void safeEncodeThrowable(final StringBuilder encoder, final Throwable throwable) {
        encoder.append("{\"type\":\"")
                .append(throwable.getClass().getName())
                .append("\",\"message\":");
        safeEncodeValue(encoder, throwable.getMessage());
        encoder.append(",\"backtrace\":[");
        for (final StackTraceElement ste : throwable.getStackTrace()) {
            safeEncodeValue(encoder, ste.toString());
            encoder.append(",");
        }
        if (throwable.getStackTrace().length == 0) {
            encoder.append("]");
        } else {
            encoder.setCharAt(encoder.length() - 1, ']');
        }
        encoder.append(",\"data\":{");
        if (throwable.getSuppressed().length > 0) {
            encoder.append("\"suppressed\":[");
            for (final Throwable suppressed : throwable.getSuppressed()) {
                safeEncodeThrowable(encoder, suppressed);
                encoder.append(",");
            }
            encoder.setCharAt(encoder.length() - 1, ']');
            encoder.append(",");
        }
        if (throwable.getCause() != null) {
            encoder.append("\"cause\":");
            safeEncodeThrowable(encoder, throwable.getCause());
            encoder.append(",");
        }
        if (encoder.charAt(encoder.length() - 1) == ',') {
            encoder.setCharAt(encoder.length() - 1, '}');
        } else {
            encoder.append("}");
        }
        encoder.append("}");
    }
/* package private