5
@JSONField的format时间格式化配置会被全局配置覆盖
@JSONField(format="yyyy-MM-dd HH:mm:ss") private Date date;
xml中
<mvc:annotation-driven conversion-service="conversionService">
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json;charset=UTF-8" />
<property name="fastJsonConfig">
<bean
class="com.alibaba.fastjson.support.config.FastJsonConfig">
<property name="serializerFeatures">
<array>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
<value>DisableCircularReferenceDetect
</value>
<value>IgnoreNonFieldGetter</value>
</array>
</property>
<property name="dateFormat" value="yyyy-MM-dd" /><!--会覆盖@JSONField的format yyyy-MM-dd HH:mm:ss-->
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
跟踪源码发现在转换javabean的时候FieldSerializer会调用到JSONSerializer的writeWithFormat 在com.alibaba.fastjson.serializer.JSONSerializer中
public final void writeWithFormat(Object object, String format) {
if (object instanceof Date) {
DateFormat dateFormat = this.getDateFormat();
if (dateFormat == null) {
dateFormat = new SimpleDateFormat(format, locale);
dateFormat.setTimeZone(timeZone);
}
String text = dateFormat.format((Date) object);
out.writeString(text);
return;
}
全局配置覆盖了传入的format,使@JSONField配置无效 请问本身就是这样设计的还是有bug