use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project starcoin-search by starcoinorg.
the class FastjsonConfiguration method fastjsonConverter.
@Bean
public HttpMessageConverters fastjsonConverter() {
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero);
FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter();
fastjson.setFastJsonConfig(fastJsonConfig);
return new HttpMessageConverters(fastjson);
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project springboot-templet-start by thedestiny.
the class WebConfiguration method fastJsonHttpMessageConverter.
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
converter.setFeatures(SerializerFeature.DisableCircularReferenceDetect);
converter.setCharset(Charset.forName("UTF-8"));
return converter;
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project ice by zjn-zjn.
the class WebMvcConfig method configureMessageConverters.
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
/*make default jackson change to fastjson*/
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastConverter.setSupportedMediaTypes(fastMediaTypes);
fastConverter.setFastJsonConfig(fastJsonConfig);
converters.add(0, fastConverter);
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project eagle-oj-api by Eagle-OJ.
the class WebMvcConfigurer method configureMessageConverters.
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
converters.add(converter);
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project fastjson by alibaba.
the class FastJsonHttpMessageConverterTest method test_read.
@SuppressWarnings("deprecation")
public void test_read() throws Exception {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
converter.setCharset(Charset.forName("UTF-8"));
Assert.assertEquals(Charset.forName("UTF-8"), converter.getCharset());
converter.setFeatures(SerializerFeature.BrowserCompatible);
Assert.assertEquals(1, converter.getFeatures().length);
Assert.assertEquals(SerializerFeature.BrowserCompatible, converter.getFeatures()[0]);
Assert.assertNull(converter.getDateFormat());
converter.setDateFormat("yyyyMMdd");
converter.setFilters(serializeFilter);
Assert.assertEquals(1, converter.getFilters().length);
Assert.assertEquals(serializeFilter, converter.getFilters()[0]);
converter.addSerializeFilter(serializeFilter);
Assert.assertEquals(2, converter.getFilters().length);
converter.addSerializeFilter(null);
converter.setSupportedMediaTypes(Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON_UTF8 }));
Assert.assertEquals(1, converter.getSupportedMediaTypes().size());
Method method = FastJsonHttpMessageConverter.class.getDeclaredMethod("supports", Class.class);
method.setAccessible(true);
method.invoke(converter, int.class);
HttpInputMessage input = new HttpInputMessage() {
public HttpHeaders getHeaders() {
// TODO Auto-generated method stub
return null;
}
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("{\"id\":123}".getBytes(Charset.forName("UTF-8")));
}
};
VO vo = (VO) converter.read(VO.class, input);
Assert.assertEquals(123, vo.getId());
final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
HttpOutputMessage out = new HttpOutputMessage() {
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
public OutputStream getBody() throws IOException {
return byteOut;
}
};
converter.write(vo, MediaType.TEXT_PLAIN, out);
byte[] bytes = byteOut.toByteArray();
Assert.assertEquals("{\"id\":\"123\"}", new String(bytes, "UTF-8"));
}
Aggregations