WRT回答以下问题:
我想知道
后续问题.
发布于 2012-06-27 19:28:42
很抱歉有人大声喊叫-我在这里找到了答案
http://wiki.fasterxml.com/JacksonFAQDateHandling,
这里
Dates,
这里
http://wiki.fasterxml.com/JacksonHowToCustomSerializers
这里
http://jackson.codehaus.org/1.1.2/javadoc/org/codehaus/jackson/map/util/StdDateFormat.html
使用@JsonSerialize(using= .)途径:
public class JsonStdDateSerializer
extends JsonSerializer<Date> {
private static final DateFormat iso8601Format =
StdDateFormat.getBlueprintISO8601Format();
@Override
public void serialize(
Date date, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
// clone because DateFormat is not thread-safe
DateFormat myformat = (DateFormat) iso8601Format.clone();
String formattedDate = myformat.format(date);
jgen.writeString(formattedDate);
}
}发布于 2013-05-01 18:45:19
这也是由ObjectMapper上的一个特性控制的(至少在1.9.11中,可能更早):
ObjectMapper om = new ObjectMapper();
om.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
om.writer().writeValue(System.out, objectWithDateProperty);我不知道如何以声明的方式对对象定义本身执行等效的操作。
https://stackoverflow.com/questions/11230954
复制相似问题