public class FastJsonpHttpMessageConverter4 extends org.springframework.http.converter.AbstractGenericHttpMessageConverter<Object>
Compatible Spring MVC version 4.2+
support to write JSONP
Configuration in xml:
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="fastJsonpResponseBodyAdvice" class="com.alibaba.fastjson.support.spring.FastJsonpResponseBodyAdvice">
<constructor-arg>
<list>
<value>callback</value>
<value>jsonp</value>
</list>
</constructor-arg>
</bean>
Configuration in java:
@EnableWebMvc
@Configuration
public class Config extends WebMvcConfigurerAdapter {
@ean
public FastJsonpResponseBodyAdvice fastJsonpResponseBodyAdvice() {
return new FastJsonpResponseBodyAdvice("callback", "jsonp");
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, new FastJsonpHttpMessageConverter4());
super.extendMessageConverters(converters);
}
}
| 构造器和说明 |
|---|
FastJsonpHttpMessageConverter4()
Can serialize/deserialize all types.
|
| 限定符和类型 | 方法和说明 |
|---|---|
FastJsonConfig |
getFastJsonConfig() |
Object |
read(Type type,
Class<?> contextClass,
org.springframework.http.HttpInputMessage inputMessage) |
void |
setFastJsonConfig(FastJsonConfig fastJsonConfig) |
canRead, canWrite, writepublic FastJsonpHttpMessageConverter4()
public FastJsonConfig getFastJsonConfig()
public void setFastJsonConfig(FastJsonConfig fastJsonConfig)
fastJsonConfig - the fastJsonConfig to set.public Object read(Type type, Class<?> contextClass, org.springframework.http.HttpInputMessage inputMessage) throws IOException, org.springframework.http.converter.HttpMessageNotReadableException
IOExceptionorg.springframework.http.converter.HttpMessageNotReadableExceptionCopyright © 2012–2016 Alibaba Group. All rights reserved.