Skip to content

Commit

Permalink
fix testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jun 1, 2024
1 parent 7c1af58 commit e058604
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ private Object readDate(JSONReader jsonReader) {
}

long millis;
if (useSimpleFormatter) {
if (useSimpleFormatter || locale != null) {
String str = jsonReader.readString();
try {
return new SimpleDateFormat(format).parse(str);
SimpleDateFormat dateFormat;
if (locale != null) {
dateFormat = new SimpleDateFormat(format, locale);
} else {
dateFormat = new SimpleDateFormat(format);
}
return dateFormat.parse(str);
} catch (ParseException e) {
throw new JSONException(jsonReader.info("parse error : " + str), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public void test6() throws Exception {
String fastjson = JSON.toJSONString(bean);
String jackson = objectMapper.writeValueAsString(bean);
assertEquals(jackson, fastjson);
//
// Bean6 parsed0 = objectMapper.readValue(jackson, Bean6.class);
// Bean6 parsed1 = JSON.parseObject(fastjson, Bean6.class);
// assertEquals(parsed0.time.getTime(), parsed1.time.getTime());

Bean6 parsed0 = objectMapper.readValue(jackson, Bean6.class);
Bean6 parsed1 = JSON.parseObject(fastjson, Bean6.class);
assertEquals(parsed0.time.getTime(), parsed1.time.getTime());
}

@Data
public static class Bean6 {
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh_CN")
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh-CN", timezone = "Asia/Shanghai")
private Date time;
}
}

0 comments on commit e058604

Please sign in to comment.