Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit cd3c2de

Browse files
committed
improved jdk8 java.time support
1 parent c63866e commit cd3c2de

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, S
174174
return (T) period;
175175
} else if (type == Duration.class) {
176176
Duration duration = Duration.parse(text);
177-
178177
return (T) duration;
179178
} else if (type == Instant.class) {
180179
boolean digit = true;
@@ -249,6 +248,12 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, S
249248
return (T) Instant.ofEpochSecond(
250249
TypeUtils.longExtractValue((Number) epochSecond));
251250
}
251+
} else if (type == Duration.class) {
252+
Long seconds = object.getLong("seconds");
253+
if (seconds != null) {
254+
long nanos = object.getLongValue("nano");
255+
return (T) Duration.ofSeconds(seconds, nanos);
256+
}
252257
}
253258
} else {
254259
throw new UnsupportedOperationException();

0 commit comments

Comments
 (0)