use of com.alibaba.fastjson.support.spring.annotation.ResponseJSONP in project uavstack by uavorg.
the class JSONPResponseBodyAdvice method beforeBodyWrite.
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
ResponseJSONP responseJsonp = returnType.getMethodAnnotation(ResponseJSONP.class);
if (responseJsonp == null) {
responseJsonp = returnType.getContainingClass().getAnnotation(ResponseJSONP.class);
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
if (!IOUtils.isValidJsonpQueryParam(callbackMethodName)) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
callbackMethodName = null;
}
JSONPObject jsonpObject = new JSONPObject(callbackMethodName);
jsonpObject.addParameter(body);
beforeBodyWriteInternal(jsonpObject, selectedContentType, returnType, request, response);
return jsonpObject;
}
use of com.alibaba.fastjson.support.spring.annotation.ResponseJSONP in project fastjson by alibaba.
the class JSONPResponseBodyAdvice method beforeBodyWrite.
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
ResponseJSONP responseJsonp = returnType.getMethodAnnotation(ResponseJSONP.class);
if (responseJsonp == null) {
responseJsonp = returnType.getContainingClass().getAnnotation(ResponseJSONP.class);
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
if (!IOUtils.isValidJsonpQueryParam(callbackMethodName)) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
callbackMethodName = null;
}
JSONPObject jsonpObject = new JSONPObject(callbackMethodName);
jsonpObject.addParameter(body);
beforeBodyWriteInternal(jsonpObject, selectedContentType, returnType, request, response);
return jsonpObject;
}
use of com.alibaba.fastjson.support.spring.annotation.ResponseJSONP in project fastjson by alibaba.
the class FastJsonViewAndJSONPControllerTest method test3.
@ResponseJSONP
@RequestMapping("test3")
@FastJsonView(include = { @FastJsonFilter(clazz = Company.class, props = { "id", "name", "rootDepartment" }), @FastJsonFilter(clazz = Department.class, props = { "description" }) })
public Company test3() {
Company company = new Company();
company.setId(100L);
company.setName("测试");
company.setDescription("fastjsonview注解测试");
company.setStock("haha");
Department department = new Department();
department.setName("部门1");
department.setDescription("部门1描述");
department.setId(1L);
company.setRootDepartment(department);
return company;
}
use of com.alibaba.fastjson.support.spring.annotation.ResponseJSONP in project fastjson by alibaba.
the class FastJsonViewAndJSONPControllerTest method test4.
@ResponseJSONP
@RequestMapping("test4")
@FastJsonView(include = { @FastJsonFilter(clazz = Company.class, props = { "id", "name", "rootDepartment" }) }, exclude = { @FastJsonFilter(clazz = Department.class, props = { "description", "memebers", "children" }) })
public Company test4() {
Company company = new Company();
company.setId(100L);
company.setName("测试");
company.setDescription("fastjsonview注解测试");
company.setStock("haha");
Department department = new Department();
department.setName("部门1");
department.setDescription("部门1描述");
department.setId(1L);
company.setRootDepartment(department);
return company;
}
use of com.alibaba.fastjson.support.spring.annotation.ResponseJSONP in project fastjson by alibaba.
the class FastJsonViewAndJSONPControllerTest method test1.
@ResponseJSONP
@RequestMapping("test1")
@FastJsonView(include = { @FastJsonFilter(clazz = Company.class, props = { "id", "name" }) })
public Company test1() {
Company company = new Company();
company.setId(100L);
company.setName("测试");
company.setDescription("fastjsonview注解测试");
company.setStock("haha");
return company;
}
Aggregations