LocalDateTime 序列化异常 Java 8 date/time type `java.time.LocalDateTime` not supported by default

抛出异常:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->com.xjc.pojo.use.Position["createDate"])

原因:

把LocalDateTime 类型的数据转换成json,会调用jsonconverter,但是jsonconverter没有办法对LocalDateTime进行序列化

需要导入依赖


      com.fasterxml.jackson.datatype
      jackson-datatype-jsr310

在需要使用不同序列化的属性使用注解

@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
    @ApiModelProperty(value = "创建时间")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createDate;

你可能感兴趣的:(Exception,java,eureka,spring,intellij-idea)