|
|
@ -26,12 +26,27 @@ public class MultiDateDeserializer extends JsonDeserializer<Date> { |
|
|
@Override |
|
|
@Override |
|
|
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { |
|
|
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { |
|
|
String text = p.getText().trim(); |
|
|
String text = p.getText().trim(); |
|
|
|
|
|
|
|
|
|
|
|
// ① 如果是纯数字 → 按时间戳处理
|
|
|
|
|
|
if (text.matches("^\\d+$")) { |
|
|
|
|
|
long t = Long.parseLong(text); |
|
|
|
|
|
|
|
|
|
|
|
// 支持:10 位秒级时间戳
|
|
|
|
|
|
if (text.length() == 10) { |
|
|
|
|
|
return new Date(t * 1000); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 支持:13 位毫秒时间戳
|
|
|
|
|
|
return new Date(t); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ② 尝试多种日期格式
|
|
|
for (String format : FORMATS) { |
|
|
for (String format : FORMATS) { |
|
|
try { |
|
|
try { |
|
|
return new SimpleDateFormat(format).parse(text); |
|
|
return new SimpleDateFormat(format).parse(text); |
|
|
} catch (ParseException ignored) { |
|
|
} catch (ParseException ignored) {} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
throw new RuntimeException("Unsupported date format: " + text); |
|
|
throw new RuntimeException("Unsupported date format: " + text); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|