Fastjson: Spring-MVC配置Date日期格式化,提示features方法过期

Created on 19 Sep 2018  ·  2Comments  ·  Source: alibaba/fastjson

image
请问有啥替代方法吗?

Most helpful comment

            <bean id="fastJsonHttpMessageConverter"
                  class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
                        <value>application/json;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
                <property name="fastJsonConfig">
                    <bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
                        <property name="charset" value="UTF-8"/>
                        <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
                        <property name="serializerFeatures">
                            <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
                                <value>PrettyFormat</value>
                                <!-- 避免循环引用 -->
                                <value>DisableCircularReferenceDetect</value>
                                <!-- 是否输出值为null的字段 -->
                                <value>WriteMapNullValue</value>
                                <!-- 数值字段如果为null,输出为0,而非null -->
                                <value>WriteNullNumberAsZero</value>
                                <!-- 字符类型字段如果为null,输出为"",而非null  -->
                                <value>WriteNullStringAsEmpty</value>
                                <!-- List字段如果为null,输出为[],而非null -->
                                <value>WriteNullListAsEmpty</value>
                                <!-- Boolean字段如果为null,输出为false,而非null -->
                                <value>WriteNullBooleanAsFalse</value>
                                <!-- 枚举输出String内容 -->
                                <value>WriteEnumUsingToString</value>
                            </array>
                        </property>
                    </bean>
                </property>
            </bean>

All 2 comments

            <bean id="fastJsonHttpMessageConverter"
                  class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
                        <value>application/json;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
                <property name="fastJsonConfig">
                    <bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
                        <property name="charset" value="UTF-8"/>
                        <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
                        <property name="serializerFeatures">
                            <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
                                <value>PrettyFormat</value>
                                <!-- 避免循环引用 -->
                                <value>DisableCircularReferenceDetect</value>
                                <!-- 是否输出值为null的字段 -->
                                <value>WriteMapNullValue</value>
                                <!-- 数值字段如果为null,输出为0,而非null -->
                                <value>WriteNullNumberAsZero</value>
                                <!-- 字符类型字段如果为null,输出为"",而非null  -->
                                <value>WriteNullStringAsEmpty</value>
                                <!-- List字段如果为null,输出为[],而非null -->
                                <value>WriteNullListAsEmpty</value>
                                <!-- Boolean字段如果为null,输出为false,而非null -->
                                <value>WriteNullBooleanAsFalse</value>
                                <!-- 枚举输出String内容 -->
                                <value>WriteEnumUsingToString</value>
                            </array>
                        </property>
                    </bean>
                </property>
            </bean>

最简单方法看源码,我也是由于对象有两个时间格式LocalDateTime和Datetime转换json报错Caused by: java.lang.IncompatibleClassChangeError: Found interface java.time.chrono.ChronoLocalDateTime, but class was expected,升级版本发现features,看源码改咯

Was this page helpful?
0 / 5 - 0 ratings