假设我有一个实体:
@Entity
@Table(name = "history_experience_entity")
@AllArgsConstructor
@NoArgsConstructor
public class HistoryExperienceEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "history_start_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd.MM.yyyy")
private LocalDate historyStartDate;
@Column(name = "history_end_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd.MM.yyyy")
private LocalDate historyEndDate;
@Column(name = "is_working")
private Boolean isWorking;
..........
}
我使用Joda LocalDate
,对于两个字段,我设置格式为"20.01.2017"
。
我邮递员发送POST请求:
{
"historyStartDate": "15.03.2016",
"historyEndDate": "30.03.2017",
"isWorking": true
}
这没有问题。但是当我有一个拥有该实体集合的DTO时:
private Set<HistoryExperienceEntity> historyExperienceEntities;
我尝试这个POST请求:
"historyExperienceEntities": [
{
"historyStartDate": "10.10.2015",
"historyEndDate": "10.10.2016",
"isWorking": false
}
]
我收到错误:
嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:格式无效:“10.10.2015”格式错误为“.10.2015”(通过参考链:com.test.service.dto.EmployeeDTO [“historyExperienceEntities”] - &GT; java.util.HashSet中[0] - &GT; com.test.domain.HistoryExperienceEntity [ “historyStartDate”])
我尝试在DTO中的集合上方添加相同的@JsonFormat
注释,但它不起作用。