org.zalando.logbook.json.JsonHttpLogFormatter Maven / Gradle / Ivy
package org.zalando.logbook.json;
import com.fasterxml.jackson.annotation.JsonRawValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.apiguardian.api.API;
import org.zalando.logbook.ContentType;
import org.zalando.logbook.HttpLogFormatter;
import org.zalando.logbook.HttpMessage;
import org.zalando.logbook.StructuredHttpLogFormatter;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import static org.apiguardian.api.API.Status.STABLE;
/**
* A custom {@link HttpLogFormatter} that produces JSON objects. It can be augmented with composition:
*
*
* {@code
*
* public class CustomsFormatter implements HttpLogFormatter {
*
* private final JsonHttpLogFormatter delegate;
*
* public CustomsFormatter(ObjectMapper mapper) {
* this.delegate = new JsonHttpLogFormatter(mapper);
* }
*
* public String format(Precorrelation precorrelation, HttpRequest request) throws IOException {
* Map content = delegate.prepare(precorrelation, request);
* // modify request here
* return delegate.format(content);
* }
*
* public String format(Correlation correlation, HttpResponse response) throws IOException {
* Map content = delegate.prepare(correlation, response);
* // modify response here
* return delegate.format(content);
* }
*
* }
* }
*
*/
@API(status = STABLE)
public final class JsonHttpLogFormatter implements StructuredHttpLogFormatter {
private final ObjectMapper mapper;
public JsonHttpLogFormatter() {
this(new ObjectMapper());
}
public JsonHttpLogFormatter(final ObjectMapper mapper) {
this.mapper = mapper;
}
@Override
public Optional © 2015 - 2025 Weber Informatics LLC | Privacy Policy