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 @ResponseJSONP in 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 JSONPObject instead.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final org.apache.commons.logging.Log
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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)
     
    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)
     
    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.
    boolean
    supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      public final org.apache.commons.logging.Log logger
  • Constructor Details

    • JSONPResponseBodyAdvice

      public JSONPResponseBodyAdvice()
  • Method Details

    • supports

      public boolean supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
      Specified by:
      supports in interface org.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:
      beforeBodyWrite in interface org.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 negotiation
      request - the current request
      response - the current response
      Returns:
      the content type to set the response to