我有一个描述从 REST 服务获取的数据的架构。我无法改变这个计划。date-time架构中有两个具有不同格式的类型字段:
"date1": {
"type": "string",
"description": "Date 1",
"format": "date-time"
},
"date2": {
"type": "string",
"description": "Date 2",
"format": "date-time"
}
Run Code Online (Sandbox Code Playgroud)
{
"date1": "2021-07-29T03:00:00",
"date2": "2021-04-22T08:25:30.264Z"
}
Run Code Online (Sandbox Code Playgroud)
date-time默认情况下,打开的 api-generator-maven-plugin 会为类型字段创建 OffsetDateTime 类型:
@JsonProperty("date1")
private OffsetDateTime date1;
@JsonProperty("date2")
private OffsetDateTime date2;
Run Code Online (Sandbox Code Playgroud)
typeMappings我可以将importMappingsOffsetDateTime 替换为 LocalDateTime:
<typeMappings>
<typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
Run Code Online (Sandbox Code Playgroud)
但这种替换将发生在所有字段上:
@JsonProperty("date1")
private LocalDateTime date1;
@JsonProperty("date2")
private LocalDateTime date2;
Run Code Online (Sandbox Code Playgroud)
有没有办法仅用 LocalDateTime 替换 OffsetDateTime date1?
这就是我想在生成的类中看到的内容:
@JsonProperty("date1")
private LocalDateTime date1;
@JsonProperty("date2")
private OffsetDateTime …Run Code Online (Sandbox Code Playgroud)