public abstract class AbstractJsonpResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice
ResponseBodyAdvice
to instruct the
MappingJackson2HttpMessageConverter
to serialize with JSONP formatting.
Sub-classes must specify the query parameter name(s) to check for the name of the JSONP callback function.
Sub-classes are likely to be annotated with the @ControllerAdvice
annotation and auto-detected or otherwise must be registered directly with the
RequestMappingHandlerAdapter
and ExceptionHandlerExceptionResolver
.
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
CALLBACK_PARAM_PATTERN
Pattern for validating jsonp callback parameter values.
|
private java.lang.String[] |
jsonpQueryParamNames |
private Log |
logger |
Modifier | Constructor and Description |
---|---|
protected |
AbstractJsonpResponseBodyAdvice(java.lang.String... queryParamNames) |
Modifier and Type | Method and Description |
---|---|
protected void |
beforeBodyWriteInternal(MappingJacksonValue bodyContainer,
MediaType contentType,
MethodParameter returnType,
ServerHttpRequest request,
ServerHttpResponse response)
Invoked only if the converter type is
MappingJackson2HttpMessageConverter . |
protected MediaType |
getContentType(MediaType contentType,
ServerHttpRequest request,
ServerHttpResponse response)
Return the content type to set the response to.
|
protected boolean |
isValidJsonpQueryParam(java.lang.String value)
Validate the jsonp query parameter value.
|
beforeBodyWrite, getOrCreateContainer, supports
private static final java.util.regex.Pattern CALLBACK_PARAM_PATTERN
private final Log logger
private final java.lang.String[] jsonpQueryParamNames
protected AbstractJsonpResponseBodyAdvice(java.lang.String... queryParamNames)
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)
AbstractMappingJacksonResponseBodyAdvice
MappingJackson2HttpMessageConverter
.beforeBodyWriteInternal
in class AbstractMappingJacksonResponseBodyAdvice
protected boolean isValidJsonpQueryParam(java.lang.String value)
value
- the query param value, never null
protected MediaType getContentType(MediaType contentType, ServerHttpRequest request, ServerHttpResponse response)
contentType
- the content type selected through content negotiationrequest
- the current requestresponse
- the current response