提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.jackson.core.databind; |
H |
2 |
|
|
3 |
import com.fasterxml.jackson.core.JsonParser; |
|
4 |
import com.fasterxml.jackson.databind.DeserializationContext; |
|
5 |
import com.fasterxml.jackson.databind.JsonDeserializer; |
|
6 |
|
|
7 |
import java.io.IOException; |
|
8 |
import java.time.Instant; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.ZoneId; |
|
11 |
|
|
12 |
/** |
|
13 |
* 基于时间戳的 LocalDateTime 反序列化器 |
|
14 |
* |
|
15 |
* @author 老五 |
|
16 |
*/ |
|
17 |
public class TimestampLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> { |
|
18 |
|
|
19 |
public static final TimestampLocalDateTimeDeserializer INSTANCE = new TimestampLocalDateTimeDeserializer(); |
|
20 |
|
|
21 |
@Override |
|
22 |
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { |
|
23 |
// 将 Long 时间戳,转换为 LocalDateTime 对象 |
|
24 |
return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getValueAsLong()), ZoneId.systemDefault()); |
|
25 |
} |
|
26 |
|
|
27 |
} |