use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule 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)));
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project xm-ms-entity by xm-online.
the class SystemQueueConsumer method consumeEvent.
/**
* Consume system event message.
*
* @param message the system event message
*/
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}", backoff = @Backoff(delayExpression = "${application.retry.delay}", multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
MdcUtils.putRid();
try {
log.info("Consume event from topic [{}]", message.topic());
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JavaTimeModule());
try {
SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
log.info("Process event from topic [{}], {}", message.topic(), event);
if (StringUtils.isBlank(event.getTenantKey())) {
log.info("Event ignored due to tenantKey is empty {}", event);
return;
}
init(event.getTenantKey(), event.getUserLogin());
systemConsumerService.acceptSystemEvent(event);
} catch (IOException e) {
log.error("System queue message has incorrect format: '{}'", message.value(), e);
}
} finally {
destroy();
}
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project xm-ms-entity by xm-online.
the class EntityToCsvConverterUtils method createDefaultCsvMapper.
private static CsvMapper createDefaultCsvMapper() {
CsvMapper mapper = new CsvMapper();
mapper.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
mapper.registerModule(new JavaTimeModule());
return mapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project xm-ms-entity by xm-online.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule 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;
}
Aggregations