java - Spring Boot 从请求中解析无效日期
问题描述
我需要在 Spring Boot(或 Jackson)上下文中解决这个问题。
不转换无效日期:31.2.2018 -> 28.2.2018 但抛出异常。
在这种情况下,我想避免为日期编写自定义序列化程序/格式化程序,并使用开箱即用的解决方案(例如 Jackson 注释或注释属性)。有这样的吗?
代码:
控制器有端点:
@PostMapping(value = "/endpoint")
public Events getAllEvents(@RequestBody EventRequest eventRequest) {}
EventRequest DTO 看起来像这样:
public class EventRequest {
private LocalDateTime eventDate;
@JsonCreator
public EventRequest(@JsonProperty(...) @JsonFormat(pattern=...) eventDate){
this.eventDate = eventDate; // 31.2.2018
// Don't want to 31.2.2018 -> 28.2.2018
// but to THROW EXCEPTION
}
}
解决方案
推荐阅读
- selenium - Selenium + sikuli 错误 - *No ClassDefFoundError: org/sikuli/script/Screen* 在命令提示符中
- python - 使用 Tensorflow 进行训练时如何正确实施验证?
- python - python在导入期间停止
- mongodb - MongoDB插入文档时出错,我该如何解决?
- python - 使用 Python 的 Elasticsearch JSON 批量索引
- react-native - React - 如何测试装饰类
- javascript - 不返回 min 但返回 Max
- java - 在 SharedPreferences 中存储图像
- android - 导入新项目时如何决定选择哪个选项?
- arrays - 如何在 ReactJS 复杂中使用读取这个数组