use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project ma-core-public by infiniteautomation.
the class MangoRestSpringConfiguration method createNewObjectMapper.
/**
* Create an instance of the Object Mapper.
* Used locally when starting Spring but may also be used for testing.
*
* Note: This is NOT the same Object Mapper instance used within a running Mango.
* XXX J.W. Seems to be used inside the REST controller to me?
*
* @return
*/
public static ObjectMapper createNewObjectMapper() {
// For raw Jackson
ObjectMapper objectMapper = new ObjectMapper();
if (Common.envProps.getBoolean("rest.indentJSON", false))
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
// JScience
JScienceModule jScienceModule = new JScienceModule();
objectMapper.registerModule(jScienceModule);
// Mango Core JSON Modules
MangoCoreModule mangoCore = new MangoCoreModule();
objectMapper.registerModule(mangoCore);
MangoRestV2JacksonModule mangoCoreV2 = new MangoRestV2JacksonModule();
objectMapper.registerModule(mangoCoreV2);
// Setup Module Defined JSON Modules
List<JacksonModuleDefinition> defs = ModuleRegistry.getDefinitions(JacksonModuleDefinition.class);
for (JacksonModuleDefinition def : defs) {
if (def.getSourceMapperType() == JacksonModuleDefinition.ObjectMapperSource.REST)
objectMapper.registerModule(def.getJacksonModule());
}
// Always output dates in ISO 8601
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
objectMapper.setDateFormat(dateFormat);
objectMapper.registerModule(new JavaTimeModule());
// Set to system tz
objectMapper.setTimeZone(TimeZone.getDefault());
// This will allow messy JSON to be imported even if all the properties in it are part of the POJOs
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project litemall by linlinjava.
the class JacksonConfig method objectMapper.
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.registerModule(javaTimeModule);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project litemall by linlinjava.
the class JacksonConfig method objectMapper.
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.registerModule(javaTimeModule);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project redisson by redisson.
the class JCacheTest method testJson.
@Test
public void testJson() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
cfg.setCodec(new TypedJsonJacksonCodec(String.class, LocalDateTime.class, objectMapper));
Configuration<String, LocalDateTime> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, LocalDateTime> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
LocalDateTime t = LocalDateTime.now();
cache.put("1", t);
Assertions.assertEquals(t, cache.get("1"));
cache.close();
runner.stop();
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project dropwizard by dropwizard.
the class Jackson method configure.
private static ObjectMapper configure(ObjectMapper mapper) {
mapper.registerModule(new GuavaModule());
mapper.registerModule(new GuavaExtrasModule());
mapper.registerModule(new CaffeineModule());
mapper.registerModule(new JodaModule());
mapper.registerModule(new BlackbirdModule());
mapper.registerModule(new FuzzyEnumModule());
mapper.registerModule(new ParameterNamesModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
return mapper;
}
Aggregations