com.fasterxml.jackson.databind.ser.std.DateSerializer Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.ser.std.DateSerializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomConfig.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
private void setConfigForJdk8(ObjectMapper objectMapper) { JavaTimeModule timeModule = new JavaTimeModule(); timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); timeModule.addSerializer(Date.class, new DateSerializer()); timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer( DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer( DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .registerModule(timeModule).registerModule(new ParameterNamesModule()) .registerModule(new Jdk8Module()); }
Example #2
Source File: CustomConfig.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
private void setConfigForJdk8(ObjectMapper objectMapper) { JavaTimeModule timeModule = new JavaTimeModule(); timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); timeModule.addSerializer(Date.class, new DateSerializer()); timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer( DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer( DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .registerModule(timeModule).registerModule(new ParameterNamesModule()) .registerModule(new Jdk8Module()); }
Example #3
Source File: CoreApplication.java From ywh-frame with GNU General Public License v3.0 | 6 votes |
/** * 时间处理 */ @Bean(name = "mapperObject") public ObjectMapper getObjectMapper() { log.debug("jackson日期时间处理"); ObjectMapper om = new ObjectMapper(); om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); om.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); JavaTimeModule javaTimeModule = new JavaTimeModule(); // serializer javaTimeModule.addSerializer(Date.class, new DateSerializer(false, new SimpleDateFormat(Constants.DEFAULT_DATE_TIME_FORMAT))); javaTimeModule.addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(Constants.DEFAULT_DATE_TIME_FORMAT))); javaTimeModule.addSerializer(LocalDate.class,new LocalDateSerializer(DateTimeFormatter.ofPattern(Constants.DEFAULT_DATE_FORMAT))); javaTimeModule.addSerializer(LocalTime.class,new LocalTimeSerializer(DateTimeFormatter.ofPattern(Constants.DEFAULT_TIME_FORMAT))); om.registerModule(javaTimeModule); return om; }
Example #4
Source File: N2oJacksonModule.java From n2o-framework with Apache License 2.0 | 4 votes |
public N2oJacksonModule(DateFormat dateFormat) { addSerializer(Date.class, new DateSerializer(false, dateFormat)); addSerializer(BigDecimal.class, new BigDecimalSerializer()); }
Example #5
Source File: Employee.java From journaldev with MIT License | 4 votes |
@JsonSerialize(using=DateSerializer.class) public Date getCreatedDate() { return createdDate; }