json里面有个日期字符串:Jan 13, 2018 12:00:00 AM
用 Json.fromJsonAsList(CampaignType.class,json);将json直接转换为对象的时候异常了
异常信息为 无法解析日期,
请问怎么处理比较好
@wendal
下面代码可以:
String date = "Jan 13, 2018 12:00:00 AM";
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss aa", Locale.ENGLISH);
System.out.println(sdf.parse(date));
但是我用@JsonField不可以
public class OfflineTimeType {
private Integer flat;
@JsonField(dataFormat = "MMM dd, yyyy HH:mm:ss aa")
private Date time;
setter...;
getter...;
}
Map map = new HashMap();
map.put("time","Jan 13, 2018 12:00:00 AM");
map.put("flag",1);
//报异常Caused by: java.lang.RuntimeException: Unexpect date format 'Jan 13, 2018 12:00:00 AM'
OfflineTimeType offlineTimeType = Json.fromJson(OfflineTimeType.class,Json.toJson(map));
@wendal 已经是最新版的了呢1.r.65-SNAPSHOT
@Test
public void LocalData() throws Exception {
LocalDate now = LocalDate.now();
HashMap<String, Object> map = new HashMap<>();
map.put("now", now);
String json = Json.toJson(now);
System.out.println(json);
// {} 打印结果
JSONAssert.assertJsonEquals(String.format("{now:%s}", now.toString()), json);
// 断言失败
}