Java Code Examples for com.alibaba.fastjson.JSON#defaultTimeZone()

The following examples show how to use com.alibaba.fastjson.JSON#defaultTimeZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultWebMvcConfigurerAdapter.java    From dk-foundation with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter fastConvert = new FastJsonHttpMessageConverter();

    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserCompatible,
            SerializerFeature.BrowserSecure,
            SerializerFeature.PrettyFormat,
            SerializerFeature.WriteDateUseDateFormat,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.DisableCircularReferenceDetect);
    /**
     * 解决Long转json精度丢失的问题
     */
    SerializeConfig serializeConfig = SerializeConfig.globalInstance;
    serializeConfig.put(BigInteger.class, ToStringSerializer.instance);
    serializeConfig.put(Long.class, ToStringSerializer.instance);
    serializeConfig.put(Long.TYPE, ToStringSerializer.instance);
    fastJsonConfig.setSerializeConfig(serializeConfig);
    fastConvert.setFastJsonConfig(fastJsonConfig);
    converters.add(fastConvert);
}