java – 用杰克逊序列化日期列表
作者:互联网
我正在尝试序列化包含日期列表的对象,并且我希望以特定格式(yyyy-MM-dd)序列化为日期(字符串)的JSON列表.
private List<Date> executionDates;
会变得像:
"executionDates": [
"2016-07-22",
"2016-07-23",
"2016-07-24"
]
可以用注释来做吗?
提前致谢.
解决方法:
我找到了解决方案.我不得不使用属性contentUsing而不是像这样在注释中使用:
@JsonSerialize(contentUsing = JsonDateSerializer.class)
contentUsing属性用于集合.从课程文档:
Serializer class to use for serializing contents (elements of a
Collection/array, values of Maps) of annotated property. Can only be
used on properties (methods, fields, constructors), and not value
classes themselves (as they are typically generic).
标签:java,json,serialization,jackson,date-format 来源: https://codeday.me/bug/20190724/1524758.html