-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathfastjson-spring.java
More file actions
50 lines (46 loc) · 1.88 KB
/
fastjson-spring.java
File metadata and controls
50 lines (46 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--------------------
FastJson-整合springmvc|
--------------------
# 普通转换器
FastJsonHttpMessageConverter
FastJsonHttpMessageConverter4
# 支持JSONP的转换器
FastJsonpHttpMessageConverter4
* 需要配置 FastJsonpResponseBodyAdvice 来指定JSONP的请求参数
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4">
<property name="supportedMediaTypes">
<list>
<value>application/json</value>
</list>
</property>
<property name="fastJsonConfig">
<bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
<property name="charset" value="UTF-8"/>
<property name="serializerFeatures">
<array>
<!-- 输出null字段 -->
<value>WriteMapNullValue</value>
<!-- 输出key使用双引号 -->
<value>QuoteFieldNames</value>
<!-- 空集合输出[] -->
<value>WriteNullListAsEmpty</value>
</array>
</property>
<!-- 日期格式 -->
<property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- jsonp 跨域 支持-->
<bean class="com.alibaba.fastjson.support.spring.FastJsonpResponseBodyAdvice">
<constructor-arg>
<list>
<value>callback</value>
<value>jsonp</value>
</list>
</constructor-arg>
</bean>