List of usage examples for com.fasterxml.jackson.datatype.jsr310 JavaTimeModule JavaTimeModule
public JavaTimeModule()
From source file:fi.helsinki.opintoni.web.WebTestUtils.java
public static byte[] toJsonBytes(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerModule(new JavaTimeModule()); return mapper.writeValueAsBytes(object); }
From source file:org.esbtools.eventhandler.lightblue.testing.LightblueClients.java
public static LightblueClient withJavaTimeSerializationSupport(LightblueClientConfiguration config) { ObjectMapper mapper = JSON.getDefaultObjectMapper().registerModule(new JavaTimeModule()); return new LightblueHttpClient(config, mapper); }
From source file:dk.dbc.kafka.logformat.LogEventMapper.java
public LogEventMapper() { objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); }
From source file:org.openmhealth.schema.configuration.JacksonConfiguration.java
public static ObjectMapper newObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); // we represent JSON numbers as Java BigDecimals objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); // we serialize dates, date times, and times as strings, not numbers objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // we preserve time zone offsets when deserializing objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); // we default to the ISO8601 format for JSR-310 and support Optional objectMapper.registerModule(new JavaTimeModule()); objectMapper.registerModule(new Jdk8Module()); // but we have to explicitly support the RFC3339 format over ISO8601 to make JSON Schema happy, specifically to // prevent the truncation of zero second fields SimpleModule rfc3339Module = new SimpleModule("rfc3339Module"); rfc3339Module.addSerializer(new Rfc3339OffsetDateTimeSerializer(OffsetDateTime.class)); objectMapper.registerModule(rfc3339Module); return objectMapper; }
From source file:com.linecorp.bot.model.message.imagemap.URIImagemapActionTest.java
@Test public void getLinkUri() throws Exception { URIImagemapAction imageMapAction = new URIImagemapAction("http://example.com", new ImagemapArea(1, 2, 3, 4)); ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()) .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); String s = objectMapper.writeValueAsString(imageMapAction); assertThat(s).contains("\"type\":\"uri\""); }
From source file:com.mesosphere.sdk.config.SerializationUtils.java
/** * Returns a new {@link ObjectMapper} with default modules against the provided factory. * * @param mapper the instance to register default modules with *//* w ww. java 2 s . com*/ public static ObjectMapper registerDefaultModules(ObjectMapper mapper) { // enable support for ... return mapper.registerModules(new GuavaModule(), // Guava types new JavaTimeModule(), // java.time.* types new Jdk8Module(), // Optional<>s new ProtobufModule()); // Protobuf objects }
From source file:com.linecorp.bot.model.profile.UserProfileResponseTest.java
@Test public void test() throws IOException { try (InputStream resourceAsStream = ClassLoader.getSystemResourceAsStream("user-profiles.json")) { ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()) .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); UserProfileResponse userProfileResponse = objectMapper.readValue(resourceAsStream, UserProfileResponse.class); assertThat(userProfileResponse.getDisplayName()).isNotNull(); }//ww w .java 2 s . c o m }
From source file:org.openapis.example.common.ObjectMapperContextResolver.java
public ObjectMapperContextResolver() { MAPPER = new ObjectMapper(); MAPPER.registerModule(new AfterburnerModule()); MAPPER.registerModule(new JavaTimeModule()); MAPPER.registerModule(new Jdk8Module()); MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); }
From source file:com.linecorp.bot.model.message.ImagemapMessageTest.java
@Test public void test() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()) .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); ImagemapMessage imagemapMessage = new ImagemapMessage("https://example.com", "hoge", new ImagemapBaseSize(1040, 1040), Collections.singletonList(new MessageImagemapAction("hoge", new ImagemapArea(0, 0, 20, 20)))); String s = objectMapper.writeValueAsString(imagemapMessage); assertThat(s).contains("\"type\":\"imagemap\""); }
From source file:com.joyent.manta.client.MantaObjectMapper.java
/** * Creates a configured instance of {@link ObjectMapper}. *//* ww w .j a v a 2 s . co m*/ public MantaObjectMapper() { registerModule(new JavaTimeModule()); DeserializationConfig deserializationConfig = getDeserializationConfig() .without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .without(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); setConfig(deserializationConfig); SerializationConfig serializationConfig = getSerializationConfig(); setConfig(serializationConfig); setSerializationInclusion(JsonInclude.Include.NON_NULL); }