我正在尝试序列化一个包含日期列表的对象,我想序列化为特定格式 (yyyy-MM-dd) 的 JSON 日期列表 (String)。
private List<Date> executionDates;
会变成这样:
"executionDates": [
"2016-07-22",
"2016-07-23",
"2016-07-24"
]
可以用注解来做吗?
提前致谢。
最佳答案
我找到了解决方案。我不得不在这样的注释中使用属性 contentUsing
而不是 using
:
@JsonSerialize(contentUsing = JsonDateSerializer.class)
contentUsing 属性用于集合。来自类(class)文档:
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 - 用 jackson 序列化日期列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38528816/