当前位置: 首页>>代码示例>>Java>>正文


Java FastJsonConfig类代码示例

本文整理汇总了Java中com.alibaba.fastjson.support.config.FastJsonConfig的典型用法代码示例。如果您正苦于以下问题:Java FastJsonConfig类的具体用法?Java FastJsonConfig怎么用?Java FastJsonConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FastJsonConfig类属于com.alibaba.fastjson.support.config包,在下文中一共展示了FastJsonConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fastJsonHttpMessageConverter

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
private FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
    FastJsonHttpMessageConverter httpMessageConverter = new FastJsonHttpMessageConverter();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames,
            SerializerFeature.WriteEnumUsingToString,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteDateUseDateFormat);
    fastJsonConfig.setSerializeFilters(new ValueFilter() {
        @Override
        public Object process(Object o, String s, Object source) {
            if (source == null) {
                return "";
            }
            if (source instanceof Date) {
                return ((Date) source).getTime();
            }
            return source;
        }
    });
    httpMessageConverter.setFastJsonConfig(fastJsonConfig);
    return httpMessageConverter;
}
 
开发者ID:helloworldtang,项目名称:sns-todo,代码行数:23,代码来源:WebMvcConfig.java

示例2: readFrom

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
/**
 * Method that JAX-RS container calls to deserialize given value.
 */
public Object readFrom(Class<Object> type, //
                       Type genericType, //
                       Annotation[] annotations, //
                       MediaType mediaType, //
                       MultivaluedMap<String, String> httpHeaders, //
                       InputStream entityStream) throws IOException, WebApplicationException {

    try {
        FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);

        return JSON.parseObject(entityStream, fastJsonConfig.getCharset(), genericType, fastJsonConfig.getFeatures());

    } catch (JSONException ex) {

        throw new WebApplicationException("JSON parse error: " + ex.getMessage(), ex);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:FastJsonProvider.java

示例3: configure

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
            String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
        return false;
    }
    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
    // Register FastJson.
    if (!config.isRegistered(FastJsonProvider.class)) {
        //DisableCircularReferenceDetect
        FastJsonProvider fastJsonProvider = new FastJsonProvider();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        //fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserSecure);

        fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);

        fastJsonProvider.setFastJsonConfig(fastJsonConfig);

        context.register(fastJsonProvider, MessageBodyReader.class, MessageBodyWriter.class);
    }
    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Issue1341.java

示例4: test_jsonp

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Test
public  void test_jsonp() throws Exception {
    FastJsonJsonView view = new FastJsonJsonView();

    Assert.assertNotNull(view.getFastJsonConfig());
    view.setFastJsonConfig(new FastJsonConfig());
    view.setExtractValueFromSingleKeyModel(true);
    view.setDisableCaching(true);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("callback", "queryName");
    MockHttpServletResponse response = new MockHttpServletResponse();


    Assert.assertEquals(true, view.isExtractValueFromSingleKeyModel());


    view.render(Collections.singletonMap("abc", "cde中文"), request, response);
    String contentAsString = response.getContentAsString();
    int contentLength = response.getContentLength();

    Assert.assertEquals(contentLength, contentAsString.getBytes(view.getFastJsonConfig().getCharset().name()).length);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:FastJsonJsonViewTest.java

示例5: configureMessageConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
/**
 * 修改自定义消息转换器
 * @param converters 消息转换器列表
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    //调用父类的配置
    super.configureMessageConverters(converters);
    //创建fastJson消息转换器
    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    
    //处理中文乱码问题
    List<MediaType> fastMediaTypes = new ArrayList<>();
    fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
    fastConverter.setSupportedMediaTypes(fastMediaTypes);
    
    //创建配置类
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    //修改配置返回内容的过滤
    fastJsonConfig.setSerializerFeatures(
            SerializerFeature.DisableCircularReferenceDetect,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullStringAsEmpty
    );
    fastConverter.setFastJsonConfig(fastJsonConfig);
    
    //将fastjson添加到视图消息转换器列表内
    converters.add(fastConverter);
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:30,代码来源:FastJsonConfiguration.java

示例6: customConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.class)
public HttpMessageConverters customConverters(FastJsonHttpMessageConverter converter) {
    Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();

    if (null == converter) {
        Class<?> converterClass = properties.getConverter();
        converter = (FastJsonHttpMessageConverter) BeanUtils.instantiate(converterClass);
    }

    FastJsonConfig config = new FastJsonConfig();
    List<SerializerFeature> features = properties.getFeatures();
    if (!CollectionUtils.isBlank(features)) {
        SerializerFeature[] featureArray = new SerializerFeature[features.size()];
        config.setSerializerFeatures(features.toArray(featureArray));
    }

    converter.setFastJsonConfig(config);
    messageConverters.add(converter);

    return new HttpMessageConverters(true, messageConverters);
}
 
开发者ID:storezhang,项目名称:utils,代码行数:23,代码来源:FastJsonAutoConfiguration.java

示例7: fastJsonHttpMessageConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
/**
 * 配置使用springmvc fastjson
 * @return
 */
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
    fastConverter.setFastJsonConfig(fastJsonConfig);
    HttpMessageConverter<?> converter = fastConverter;
    return new HttpMessageConverters(converter);
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:14,代码来源:WebConfig.java

示例8: configureMessageConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig config = new FastJsonConfig();
    config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,//保留空的字段
            SerializerFeature.WriteNullStringAsEmpty,//String null -> ""
            SerializerFeature.WriteNullNumberAsZero);//Number null -> 0
    converter.setFastJsonConfig(config);
    converter.setDefaultCharset(Charset.forName("UTF-8"));
    converters.add(converter);
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:12,代码来源:WebMvcConfig.java

示例9: configureMessageConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
/**
 * 配置fastJson
 * @param converters
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
    fastConverter.setFastJsonConfig(fastJsonConfig);
    converters.add(fastConverter);
    super.configureMessageConverters(converters);
}
 
开发者ID:leon66666,项目名称:spring-boot-frameset,代码行数:14,代码来源:MyWebMvcConfigurerAdapter.java

示例10: fastJsonHttpMessageConverter

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean({ FastJsonHttpMessageConverter4.class })
//当没有注册这个类时,自动注册Bean
public FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter() {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();

    //使用最新的官方推荐配置对象的方式来注入fastjson的序列化特征
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(
            SerializerFeature.WriteDateUseDateFormat,
            SerializerFeature.WriteNullListAsEmpty,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullBooleanAsFalse,
            SerializerFeature.WriteNullStringAsEmpty
     );
    
    //添加对json值的过滤,因为像移动APP,服务端在传json值时最好不要传null,而是使用“”,这是一个演示
    ValueFilter valueFilter = new ValueFilter() {//5
        //o 是class
        //s 是key值
        //o1 是value值
        public Object process(Object o, String s, Object o1) {
            if (null == o1) {
                o1 = "";
            }
            return o1;
        }
    };
    fastJsonConfig.setSerializeFilters(valueFilter);

    converter.setFastJsonConfig(fastJsonConfig);

    return converter;
}
 
开发者ID:qjx378,项目名称:wenku,代码行数:35,代码来源:FastJsonHttpMessageConvertersConfiguration.java

示例11: registry

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Override
public void registry(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter4();
    ArrayList<MediaType> arrayList = new ArrayList<MediaType>() {{
        add(MediaType.APPLICATION_JSON_UTF8);
        add(MediaType.valueOf("text/html;charset=UTF-8"));
        add(MediaType.MULTIPART_FORM_DATA);
    }};
    fastJsonHttpMessageConverter.setSupportedMediaTypes(arrayList);
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames,
            SerializerFeature.DisableCircularReferenceDetect);
    fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
    converters.add(0, fastJsonHttpMessageConverter);
}
 
开发者ID:ismartx,项目名称:summer,代码行数:16,代码来源:DefaultFastJsonMessageConverterRegister.java

示例12: fastJsonHttpMessageConverters

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverters() {
    ParserConfig.getGlobalInstance().setAutoTypeSupport(true);

    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
    fastConverter.setFastJsonConfig(fastJsonConfig);

    return fastConverter;
}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:12,代码来源:MvcConfig.java

示例13: getFastJsonConfig

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
public FastJsonConfig getFastJsonConfig() {
    return fastJsonConfig;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:FastJsonRedisSerializer.java

示例14: setFastJsonConfig

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
    this.fastJsonConfig = fastJsonConfig;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:FastJsonRedisSerializer.java

示例15: writeTo

import com.alibaba.fastjson.support.config.FastJsonConfig; //导入依赖的package包/类
/**
     * Method that JAX-RS container calls to serialize given value.
     */
    public void writeTo(Object obj, //
                        Class<?> type, //
                        Type genericType, //
                        Annotation[] annotations, //
                        MediaType mediaType, //
                        MultivaluedMap<String, Object> httpHeaders, //
                        OutputStream entityStream //
    ) throws IOException, WebApplicationException {

        FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);

        SerializerFeature[] serializerFeatures = fastJsonConfig.getSerializerFeatures();
        if (pretty) {
            if (serializerFeatures == null)
                serializerFeatures = new SerializerFeature[]{SerializerFeature.PrettyFormat};
            else {
                List<SerializerFeature> featureList = new ArrayList<SerializerFeature>(Arrays
                        .asList(serializerFeatures));
                featureList.add(SerializerFeature.PrettyFormat);
                serializerFeatures = featureList.toArray(serializerFeatures);
            }
            fastJsonConfig.setSerializerFeatures(serializerFeatures);
        }

        try {
            int len = JSON.writeJSONString(entityStream, //
                    fastJsonConfig.getCharset(), //
                    obj, //
                    fastJsonConfig.getSerializeConfig(), //
                    fastJsonConfig.getSerializeFilters(), //
                    fastJsonConfig.getDateFormat(), //
                    JSON.DEFAULT_GENERATE_FEATURE, //
                    fastJsonConfig.getSerializerFeatures());

//            // add Content-Length
//            if (fastJsonConfig.isWriteContentLength()) {
//                httpHeaders.add("Content-Length", String.valueOf(len));
//            }

            entityStream.flush();

        } catch (JSONException ex) {

            throw new WebApplicationException("Could not write JSON: " + ex.getMessage(), ex);
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:50,代码来源:FastJsonProvider.java


注:本文中的com.alibaba.fastjson.support.config.FastJsonConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。