How to set format of string for java.time.Instant using objectMapper?

后端 未结 7 851
失恋的感觉
失恋的感觉 2020-11-29 04:37

I have an entity with java.time.Instant for created data field:

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public         


        
7条回答
  •  迷失自我
    2020-11-29 05:03

    If using Spring, and spring-web is on the classpath, you can create an ObjectMapper using the Jackson2ObjectMapperBuilder. It registers the following commonly used modules within the method registerWellKnownModulesIfAvailable.

    com.fasterxml.jackson.datatype.jdk8.Jdk8Module
    com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
    com.fasterxml.jackson.datatype.joda.JodaModule
    com.fasterxml.jackson.module.kotlin.KotlinModule
    

    Some of these modules have been merged into Jackson 3; see here.

提交回复
热议问题