Search in sources :

Example 1 with JodaTimePeriodKeyDeserializer

use of org.graylog2.jackson.JodaTimePeriodKeyDeserializer 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 2 with JodaTimePeriodKeyDeserializer

use of org.graylog2.jackson.JodaTimePeriodKeyDeserializer in project graylog2-server by Graylog2.

the class QueryTest method setup.

@Before
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) Before(org.junit.Before)

Aggregations

MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)2 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)2 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)2 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)2 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)2 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)2 StreamFilter (org.graylog.plugins.views.search.filter.StreamFilter)2 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)2 ObjectIdSerializer (org.graylog2.database.ObjectIdSerializer)2 JodaTimePeriodKeyDeserializer (org.graylog2.jackson.JodaTimePeriodKeyDeserializer)2 SizeSerializer (org.graylog2.shared.jackson.SizeSerializer)2 RangeJsonSerializer (org.graylog2.shared.rest.RangeJsonSerializer)2 Period (org.joda.time.Period)2 Before (org.junit.Before)1 Test (org.junit.Test)1