Search in sources :

Example 1 with FastJsonView

use of com.alibaba.fastjson.support.spring.annotation.FastJsonView in project fastjson by alibaba.

the class FastJsonViewControllerTest method test6.

@RequestMapping("test6")
@FastJsonView(include = { @FastJsonFilter(clazz = Company.class, props = { "id" }) }, exclude = { @FastJsonFilter(clazz = Company.class, props = { "name" }) })
@ResponseBody
public Company test6() {
    Company company = new Company();
    company.setId(100L);
    company.setName("测试");
    company.setDescription("fastjsonview注解测试");
    company.setStock("haha");
    return company;
}
Also used : Company(com.alibaba.json.test.entity.Company) FastJsonView(com.alibaba.fastjson.support.spring.annotation.FastJsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with FastJsonView

use of com.alibaba.fastjson.support.spring.annotation.FastJsonView in project fastjson by alibaba.

the class FastJsonViewControllerTest method test4.

@RequestMapping("test4")
@FastJsonView(include = { @FastJsonFilter(clazz = Company.class, props = { "id", "name", "rootDepartment" }) }, exclude = { @FastJsonFilter(clazz = Department.class, props = { "description" }) })
@ResponseBody
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;
}
Also used : Company(com.alibaba.json.test.entity.Company) Department(com.alibaba.json.test.entity.Department) FastJsonView(com.alibaba.fastjson.support.spring.annotation.FastJsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with FastJsonView

use of com.alibaba.fastjson.support.spring.annotation.FastJsonView in project fastjson by alibaba.

the class FastJsonViewControllerTest method test2.

@RequestMapping("test2")
@FastJsonView(exclude = { @FastJsonFilter(clazz = Company.class, props = { "id", "name" }) })
@ResponseBody
public Company test2() {
    Company company = new Company();
    company.setId(100L);
    company.setName("测试");
    company.setDescription("fastjsonview注解测试");
    company.setStock("haha");
    return company;
}
Also used : Company(com.alibaba.json.test.entity.Company) FastJsonView(com.alibaba.fastjson.support.spring.annotation.FastJsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with FastJsonView

use of com.alibaba.fastjson.support.spring.annotation.FastJsonView in project fastjson by alibaba.

the class FastJsonViewResponseBodyAdvice method beforeBodyWriteInternal.

protected void beforeBodyWriteInternal(FastJsonContainer container, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
    FastJsonView annotation = returnType.getMethodAnnotation(FastJsonView.class);
    FastJsonFilter[] include = annotation.include();
    FastJsonFilter[] exclude = annotation.exclude();
    PropertyPreFilters filters = new PropertyPreFilters();
    for (FastJsonFilter item : include) {
        filters.addFilter(item.clazz(), item.props());
    }
    for (FastJsonFilter item : exclude) {
        filters.addFilter(item.clazz()).addExcludes(item.props());
    }
    container.setFilters(filters);
}
Also used : FastJsonFilter(com.alibaba.fastjson.support.spring.annotation.FastJsonFilter) FastJsonView(com.alibaba.fastjson.support.spring.annotation.FastJsonView)

Example 5 with FastJsonView

use of com.alibaba.fastjson.support.spring.annotation.FastJsonView in project uavstack by uavorg.

the class FastJsonViewResponseBodyAdvice method beforeBodyWriteInternal.

protected void beforeBodyWriteInternal(FastJsonContainer container, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
    FastJsonView annotation = returnType.getMethodAnnotation(FastJsonView.class);
    FastJsonFilter[] include = annotation.include();
    FastJsonFilter[] exclude = annotation.exclude();
    PropertyPreFilters filters = new PropertyPreFilters();
    for (FastJsonFilter item : include) {
        filters.addFilter(item.clazz(), item.props());
    }
    for (FastJsonFilter item : exclude) {
        filters.addFilter(item.clazz()).addExcludes(item.props());
    }
    container.setFilters(filters);
}
Also used : FastJsonFilter(com.alibaba.fastjson.support.spring.annotation.FastJsonFilter) FastJsonView(com.alibaba.fastjson.support.spring.annotation.FastJsonView)

Aggregations

FastJsonView (com.alibaba.fastjson.support.spring.annotation.FastJsonView)12 Company (com.alibaba.json.test.entity.Company)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Department (com.alibaba.json.test.entity.Department)5 ResponseJSONP (com.alibaba.fastjson.support.spring.annotation.ResponseJSONP)4 FastJsonFilter (com.alibaba.fastjson.support.spring.annotation.FastJsonFilter)2