use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpoint method configureJsonMapper.
/**
* Configure Jackson's {@link JsonMapper} to be used to serialize the
* {@link ConfigurationProperties @ConfigurationProperties} objects into a {@link Map}
* structure.
* @param builder the json mapper builder
* @since 2.6.0
*/
protected void configureJsonMapper(JsonMapper.Builder builder) {
builder.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
builder.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
builder.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
JsonMapper.builder();
builder.configure(MapperFeature.USE_STD_BEAN_NAMING, true);
builder.serializationInclusion(Include.NON_NULL);
applyConfigurationPropertiesFilter(builder);
applySerializationModifier(builder);
builder.addModule(new JavaTimeModule());
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project snow-owl by b2ihealthcare.
the class RestExtensions method givenUnauthenticatedRequest.
public static RequestSpecification givenUnauthenticatedRequest(String api) {
if (INITIALIZE_ONCE.compareAndSet(false, true)) {
// change Base URI if defined as sysarg
final String serverLocation = System.getProperty("test.server.location");
if (!Strings.isNullOrEmpty(serverLocation)) {
RestAssured.baseURI = serverLocation;
}
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(ObjectMapperConfig.objectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {
@Override
public com.fasterxml.jackson.databind.ObjectMapper create(Type arg0, String arg1) {
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
mapper.registerModule(new JavaTimeModule());
// bbanfai: added date format
final StdDateFormat dateFormat = new StdDateFormat();
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
mapper.setDateFormat(dateFormat);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return mapper;
}
})).logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails());
}
Preconditions.checkArgument(api.startsWith("/"), "Api param should start with a forward slash: '/'");
return given().port(getPort()).basePath(CONTEXT + api);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class JsonFormatter method format.
public String format(Object value) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.registerModule(new JavaTimeModule());
return mapper.writer().writeValueAsString(Objects.requireNonNull(value));
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project oap by oaplatform.
the class Binder method initialize.
private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
if (mapper instanceof XmlMapper) {
((XmlMapper) mapper).setDefaultUseWrapper(false);
((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
}
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
mapper.getDeserializationConfig().with(introspector);
mapper.getSerializationConfig().with(introspector);
mapper.registerModule(new AfterburnerModule());
mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
mapper.registerModule(new JodaModule());
mapper.registerModule(new ExtModule());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
// todo remove after kernel cleanup
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
if (skipInputNulls)
mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
if (!nonNullInclusion)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
modules.forEach(mapper::registerModule);
if (defaultTyping)
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
return mapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project eap-additional-testsuite by jboss-set.
the class Jsr310DeserializationTestCase method testInstantDeserialization.
@Test
public void testInstantDeserialization() throws Exception {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
final String INPUT = "1e10000000";
// this should return almost instantly
Instant value = mapper.readValue(INPUT, Instant.class);
Assert.assertEquals("Didn't get the expected value.", 0, value.getEpochSecond());
}
Aggregations