org.graylog2.telemetry.providers.ObjectMapperProvider Maven / Gradle / Ivy
package org.graylog2.telemetry.providers;
import com.codahale.metrics.json.MetricsModule;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import org.graylog2.telemetry.TelemetryNodeService;
import javax.inject.Provider;
import static java.util.concurrent.TimeUnit.SECONDS;
public class ObjectMapperProvider implements Provider {
private final ObjectMapper objectMapper;
public ObjectMapperProvider() {
final SmileFactory smileFactory = new SmileFactory()
.disable(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT)
.enable(SmileGenerator.Feature.WRITE_END_MARKER);
objectMapper = new ObjectMapper(smileFactory)
.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
.registerModule(new JodaModule())
.registerModule(new GuavaModule())
.registerModule(new MetricsModule(SECONDS, SECONDS, false, TelemetryNodeService.METRICS_FILTER));
}
@Override
public ObjectMapper get() {
return objectMapper;
}
}