forest icon indicating copy to clipboard operation
forest copied to clipboard

反序列化offsetdatetime时失败

Open oonxt opened this issue 3 years ago • 1 comments

error: json converter: 'ForestJacksonConverter' error: Java 8 date/time type java.time.OffsetDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

oonxt avatar Jul 26 '22 06:07 oonxt

jackson默认不支持java8的时间类型,需要添加一个时间模块

<dependency>
	<groupId>com.fasterxml.jackson.datatype</groupId>
	<artifactId>jackson-datatype-jsr310</artifactId>
	<version>2.13.3</version>
</dependency>

再通过@Bean方法定义 ForestJacksonConverter bean进行配置

@Bean
public ForestJsonConverter forestJacksonConverter() {
    ForestJacksonConverter converter = new ForestJacksonConverter();
    ObjectMapper mapper = converter.getMapper();
    mapper.findAndRegisterModules();
    return converter;
}

mySingleLive avatar Jul 29 '22 16:07 mySingleLive