Class JSONPResponseBodyAdvice
- java.lang.Object
-
- com.alibaba.fastjson.support.spring.JSONPResponseBodyAdvice
-
- All Implemented Interfaces:
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice<Object>
@Order(-2147483648) @ControllerAdvice public class JSONPResponseBodyAdvice extends Object implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice<Object>
Created by SongLing.Dong on 7/22/2017.Wrap with the return object from method annotated by
@ResponseJSONPin order to be serialized into jsonp format.url: /path/to/your/api?callback=functionName
- Since:
- Spring 4.2 when ResponseBodyAdvice is supported.
In Spring 3.x, use method directly return a
JSONPObjectinstead. - See Also:
JSONPObject,ResponseJSONP
-
-
Field Summary
Fields Modifier and Type Field Description org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description JSONPResponseBodyAdvice()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectbeforeBodyWrite(Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)voidbeforeBodyWriteInternal(JSONPObject jsonpObject, org.springframework.http.MediaType contentType, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)protected org.springframework.http.MediaTypegetContentType(org.springframework.http.MediaType contentType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)Return the content type to set the response to.booleansupports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
-
-
-
Method Detail
-
supports
public boolean supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)- Specified by:
supportsin interfaceorg.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice<Object>
-
beforeBodyWrite
public Object beforeBodyWrite(Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)
- Specified by:
beforeBodyWritein interfaceorg.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice<Object>
-
beforeBodyWriteInternal
public void beforeBodyWriteInternal(JSONPObject jsonpObject, org.springframework.http.MediaType contentType, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)
-
getContentType
protected org.springframework.http.MediaType getContentType(org.springframework.http.MediaType contentType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)Return the content type to set the response to. This implementation always returns "application/javascript".- Parameters:
contentType- the content type selected through content negotiationrequest- the current requestresponse- the current response- Returns:
- the content type to set the response to
-
-