Skip to content

Commit

Permalink
deserialize java.util.Date support input time string, for issue #2905
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 1, 2024
1 parent d2a1066 commit 8572567
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ private Object readDate(JSONReader jsonReader) {
int length = yyyyMMddhhmm16 ? 16 : 19;
ldt = DateUtils.parseLocalDateTime(str, 0, length);
} else {
ldt = LocalDateTime.parse(str, formatter);
if (formatHasDay) {
ldt = LocalDateTime.parse(str, formatter);
} else {
LocalTime localTime = LocalTime.parse(str, formatter);
ldt = LocalDateTime.of(LocalDate.MIN, localTime);
}
}
}
zdt = ldt.atZone(jsonReader.getContext().getZoneId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.alibaba.fastjson2.issues_2900;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class Issue2905 {
@Test
public void test() {
String s = "{\"saleEndTime\": \"23:00:00\"}";
Bean order = JSON.parseObject(s, Bean.class);
assertNotNull(order.saleEndTime);
}

public static class Bean {
@JSONField(format = "HH:mm:ss")
public Date saleEndTime;
}
}

0 comments on commit 8572567

Please sign in to comment.