All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockserver.dashboard.serializers.ThrowableSerializer Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.dashboard.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;

public class ThrowableSerializer extends StdSerializer {
    public ThrowableSerializer() {
        super(Throwable.class);
    }

    @Override
    public void serialize(final Throwable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException {
        final String stackTrace = getStackTrace(value);
        final String[] lines = stackTrace.split("\n");
        if (lines.length > 1) {
            gen.writeObject(lines);
        } else {
            gen.writeString(stackTrace);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy