com.alibaba.fastjson.serializer.ToStringSerializer Java Examples

The following examples show how to use com.alibaba.fastjson.serializer.ToStringSerializer. 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);
}
 
Example #2
Source File: DefaultFastjsonConfig.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
/**
 * fastjson的配置
 */
public FastJsonConfig fastjsonConfig() {
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(
            SerializerFeature.PrettyFormat,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteEnumUsingToString
    );
    fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
    ValueFilter valueFilter = new ValueFilter() {
        public Object process(Object o, String s, Object o1) {
            if (null == o1) {
                o1 = "";
            }
            return o1;
        }
    };
    fastJsonConfig.setCharset(Charset.forName("utf-8"));
    fastJsonConfig.setSerializeFilters(valueFilter);

    //解决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);
    return fastJsonConfig;
}
 
Example #3
Source File: DefaultFastjsonConfig.java    From flash-waimai with MIT License 5 votes vote down vote up
/**
 * fastjson的配置
 */
public FastJsonConfig fastjsonConfig() {
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(
            SerializerFeature.PrettyFormat,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteEnumUsingToString,
            SerializerFeature.DisableCircularReferenceDetect
    );
    fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
    ValueFilter valueFilter = new ValueFilter() {
        @Override
        public Object process(Object o, String s, Object o1) {
            if (null == o1) {
                o1 = "";
            }
            return o1;
        }
    };
    fastJsonConfig.setCharset(Charset.forName("utf-8"));
    fastJsonConfig.setSerializeFilters(valueFilter);

    //解决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);
    return fastJsonConfig;
}
 
Example #4
Source File: FastJsonSerializeConfig.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setSerializers(Map<Type, ObjectSerializer> dest){
    this.put(BigInteger.class, ToStringSerializer.instance);
    this.put(Long.class, ToStringSerializer.instance);
    this.put(Long.TYPE, ToStringSerializer.instance);
    if (CollectionUtil.isNotEmpty(dest)){
        for (Entry<Type, ObjectSerializer> entry :dest.entrySet()){
            this.put(entry.getKey(), entry.getValue());
        }
    }
}