Java 集合中Joda LocalDate的格式问题无效
假设我有一个实体:Java 集合中Joda LocalDate的格式问题无效,java,rest,jackson,jodatime,localdate,Java,Rest,Jackson,Jodatime,Localdate,假设我有一个实体: @Entity @Table(name = "history_experience_entity") @AllArgsConstructor @NoArgsConstructor public class HistoryExperienceEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = Gener
@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;
..........
}
我使用JodaLocalDate
,对两个字段设置格式,如“20.01.2017”
。
我通过邮递员发送邮寄请求:
{
"historyStartDate": "15.03.2016",
"historyEndDate": "30.03.2017",
"isWorking": true
}
这没有问题。但当我有一个DTO,它有一个这个实体的集合:
private Set<HistoryExperienceEntity> historyExperienceEntities;
我得到一个错误:
嵌套异常为com.fasterxml.jackson.databind.JsonMappingException:无效格式:“10.10.2015”在.10.2015处格式不正确(通过引用链:com.test.service.dto.EmployeeDTO[“historyExperienceEntities”]->java.util.HashSet[0]->com.test.domain.HistoryExperienceEntity[“historyStartDate”])
我试图在DTO中的集合上方添加相同的
@JsonFormat
注释,但没有成功。我创建了反序列化程序,但我创建了反序列化程序。
"historyExperienceEntities": [
{
"historyStartDate": "10.10.2015",
"historyEndDate": "10.10.2016",
"isWorking": false
}
]