【发布时间】:2021-12-09 10:06:02
【问题描述】:
我在我的 spring boot webapp 中配置了一个 FeignClient,我正在调用一个返回以下对象的外部 api。
public class Issue {
private Assignee assignee;
private Date createdAt;
private Date updatedAt;
private Date closedAt;
private String description;
private Date dueDate;
public Assignee getAssignee() {
return assignee;
}
public void setAssignee(Assignee assignee) {
this.assignee = assignee;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Date getClosedAt() {
return closedAt;
}
public void setClosedAt(Date closedAt) {
this.closedAt = closedAt;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
updatedAt、createdAt 和 closedAt 字段都在蛇形案例中。所有多字字段都显示为空。有没有办法配置 FeignClient 的 Jackson 解析器,以便它可以处理蛇大小写字符?请注意,我无法更改我的 spring boot webapp 的默认 Jackson Parser,因为我自己在驼峰式案例中渲染 json。我只需要在我用来连接外部 REST api 的 FeignClient 上配置这个解析器。
我已验证从 api 调用返回的 json 响应在每个 json 字段中都包含有效值。
【问题讨论】:
-
如果您在 createdAt 字段上使用 JsonProperty("created_At") 或者无法添加注释,结果保持不变?
标签: spring-boot jackson spring-cloud-feign