Search in sources :

Example 6 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project graylog2-server by Graylog2.

the class InMemorySearchJobServiceTest method setup.

@Test
public void setup() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final TypeFactory typeFactory = mapper.getTypeFactory().withClassLoader(this.getClass().getClassLoader());
    this.objectMapper = mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE).setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy()).setTypeFactory(typeFactory).registerModule(new GuavaModule()).registerModule(new JodaModule()).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()).registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)).registerModule(new SimpleModule("Graylog").addKeyDeserializer(Period.class, new JodaTimePeriodKeyDeserializer()).addSerializer(new RangeJsonSerializer()).addSerializer(new SizeSerializer()).addSerializer(new ObjectIdSerializer()));
    // kludge because we don't have an injector in tests
    ImmutableMap<String, Class> subtypes = ImmutableMap.<String, Class>builder().put(StreamFilter.NAME, StreamFilter.class).put(ElasticsearchQueryString.NAME, ElasticsearchQueryString.class).put(MessageList.NAME, MessageList.class).build();
    subtypes.forEach((name, klass) -> objectMapper.registerSubtypes(new NamedType(klass, name)));
}
Also used : SizeSerializer(org.graylog2.shared.jackson.SizeSerializer) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Period(org.joda.time.Period) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JodaTimePeriodKeyDeserializer(org.graylog2.jackson.JodaTimePeriodKeyDeserializer) MetricsModule(com.codahale.metrics.json.MetricsModule) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) ObjectIdSerializer(org.graylog2.database.ObjectIdSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) RangeJsonSerializer(org.graylog2.shared.rest.RangeJsonSerializer) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Example 7 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project graylog2-server by Graylog2.

the class UrlWhitelistTest method serializationRoundtrip.

@Test
public void serializationRoundtrip() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    List<WhitelistEntry> entries = ImmutableList.of(LiteralWhitelistEntry.create("a", "title", "https://www.graylog.com"), RegexWhitelistEntry.create("b", "regex test title", "https://www\\.graylog\\.com/.*"));
    UrlWhitelist orig = UrlWhitelist.createEnabled(entries);
    String json = objectMapper.writeValueAsString(orig);
    UrlWhitelist read = objectMapper.readValue(json, UrlWhitelist.class);
    assertThat(read).isEqualTo(orig);
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project keywhiz by square.

the class KeywhizService method customizeObjectMapper.

/**
 * Customizes ObjectMapper for common settings.
 *
 * @param objectMapper to be customized
 * @return customized input factory
 */
public static ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) {
    objectMapper.registerModules(new Jdk8Module());
    objectMapper.registerModules(new JavaTimeModule());
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return objectMapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)

Example 9 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project keywhiz by square.

the class CliModule method generalMapper.

@Provides
public ObjectMapper generalMapper() {
    /**
     * Customizes ObjectMapper for common settings.
     *
     * @param objectMapper to be customized
     * @return customized input factory
     */
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModules(new JavaTimeModule());
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Provides(com.google.inject.Provides)

Example 10 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project vespa by vespa-engine.

the class DeployOptionsTest method it_serializes_version.

@Test
public void it_serializes_version() throws IOException {
    DeployOptions options = new DeployOptions(Optional.empty(), Optional.of(new Version("6.98.227")), false, false);
    final ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).registerModule(new Jdk8Module());
    String string = objectMapper.writeValueAsString(options);
    assertEquals("{\"screwdriverBuildJob\":null,\"vespaVersion\":\"6.98.227\",\"ignoreValidationErrors\":false,\"deployCurrentVersion\":false}", string);
}
Also used : DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Version(com.yahoo.component.Version) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)159 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)128 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)68 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)31 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)26 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)22 IOException (java.io.IOException)19 Bean (org.springframework.context.annotation.Bean)14 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)10 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)8 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)8 JSONObject (org.json.JSONObject)8 Autowired (org.springframework.beans.factory.annotation.Autowired)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)5 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)5 Action (io.syndesis.common.model.action.Action)5 Test (org.junit.jupiter.api.Test)5