我最近尝试使用spring-boot 2实现微服务。
现在,每当我尝试java.time.LocalDateTime
从REST服务返回包含的对象时,LocalDateTime都会序列化为整数数组。像这样:
{
"id": "5bf1425f9f8de267f04b22ad",
"description": "aaaaaarrrgggghhhhh",
"timestamp": [
2018,
11,
18,
11,
43,
43,
889000000
],
"time": 2.25,
...
}
Run Code Online (Sandbox Code Playgroud)
我尝试在中配置ObjectMapper
通过设置application.yml
spring:
jackson:
serialization:
write-dates-as-timestamps: false
Run Code Online (Sandbox Code Playgroud)
但不起作用。我还尝试通过Spring Configuration类配置新的ObjectMapper,如下所示:
spring:
jackson:
serialization:
write-dates-as-timestamps: false
Run Code Online (Sandbox Code Playgroud)
我的配置被加载(调试器在断点处停止)-只是它什么都不做。
我尝试将jackson
依赖项手动添加(也用于jsr310模块)到pom.xml-也没有任何运气。
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,Spring Boot似乎忽略了我使用ObjectMapper进行任何尝试的尝试,并且一直返回相同的结果。
com.fasterxml
在中将日志级别设置为DEBUG application.yml
也不会产生任何输出:
logging:
level:
com.fasterxml: DEBUG
Run Code Online (Sandbox Code Playgroud)
我在Jackson 2.9.7中使用Spring Boot 2.1.0-RELEASE。
基本的pom文件是从https://start.spring.io生成的。我的项目针对Java 8 JVM进行编译并在其上运行。