0
点赞
收藏
分享

微信扫一扫

LocalDateTime兼容日期格式

妖妖妈 2023-11-06 阅读 53

public class CustomDeserializer extends JsonDeserializer<LocalDateTime> {
//兼容生长曲线纪录中前端可能会传递的recordTime格式为yyyy-MM-d HH:mm:ss的参数
public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d HH:mm:ss");
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws RuntimeException {
try{
if(p !=null && StringUtils.isNotEmpty(p.getText())){
return LocalDateTime.parse(p.getText(),format);
}else{
return null;
}
}catch (Exception e){
System.out.println(e.getMessage());
throw new RuntimeException();
}

举报

相关推荐

0 条评论