第一步、时间格式化工具
第三步、在对象属性中加入自定义json的处理日期转换类
public static synchronized String getDateSecondFormat(java.util.Date date) {
return getDateFormat(date, "yyyy-MM-dd");
}
</pre><pre code_snippet_id="541609" snippet_file_name="blog_20141204_3_1696394" name="code" class="java">第二步、自定义json的处理日期转换类
</pre><pre code_snippet_id="541609" snippet_file_name="blog_20141204_5_7043101" name="code" class="java">public class CustomJsonDateSerializer extends JsonSerializer<Date> {
/*
* (non-Javadoc)
*
* @see org.codehaus.jackson.map.JsonSerializer#serialize(java.lang.Object,
* org.codehaus.jackson.JsonGenerator,
* org.codehaus.jackson.map.SerializerProvider)
*/
@Override
public void serialize(Date value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
jgen.writeString(DateUtil.getDateSecondFormat(value));
}
}
第三步、在对象属性中加入自定义json的处理日期转换类
/**
* @return the modifyDate
*/
@JsonSerialize(using = CustomJsonDateSerializer.class)
public Date getModifyDate() {
return modifyDate;
}
这样就完成json处理对象返回自定义属性了