Spring boot 带JsonView的Springboot大摇大摆

Spring boot 带JsonView的Springboot大摇大摆,spring-boot,swagger-ui,json-view,Spring Boot,Swagger Ui,Json View,可以将招摇过市与@JsonView?我有一个模型,我使用@JsonView只返回几个字段,但是swagger用户界面显示了孔模型 这是我的模型: public class Intimacao extends EntityBase { @Embedded @JsonView({View.Intimacao_Lista.class}) private Devedor devedor; @Embedded private Sacador sacador;

可以将招摇过市与
@JsonView
?我有一个模型,我使用
@JsonView
只返回几个字段,但是swagger用户界面显示了孔模型

这是我的模型:

public class Intimacao extends EntityBase {
    @Embedded
    @JsonView({View.Intimacao_Lista.class})
    private Devedor devedor;
    @Embedded
    private Sacador sacador;
    @Embedded
    private Apresentante apresentante;
    @Embedded
    private Titulo titulo;

}
这是我的控制器:

@GetMapping("/")
@PreAuthorize("hasRole('ADMINISTRADOR') or hasRole('MOTOBOY')")
@JsonView({View.Intimacao_Lista.class})
public List<Intimacao> listar(Principal principal){
    System.out.println(principal.getName());
    return null;
}
但是如果我
GET
我的API只会返回
devedor
属性,因为
@JsonView

可以将招摇过市与
@JsonView

是(部分)

合并后,您可以将其用于:

响应对象(您已使该部分正常工作)

@GetMapping(“/”)
@预授权(“hasRole('Administrator')或hasRole('MOTOBOY'))
@JsonView({View.com\u Lista.class})
公共列表列表(委托人){
System.out.println(principal.getName());
返回null;
}
RequestBody对象(还没有,请在途中拉取请求,请参阅和中的示例)。就你而言:

@GetMapping("/")
@PreAuthorize("hasRole('ADMINISTRADOR') or hasRole('MOTOBOY')")
@JsonView({View.Intimacao_Lista.class})
// replace `Views.Principal.class` for the proper value
public List<Intimacao> listar(@JsonView(Views.Principal.class) Principal principal){
    System.out.println(principal.getName());
    return null;
}
@GetMapping(“/”)
@预授权(“hasRole('Administrator')或hasRole('MOTOBOY'))
@JsonView({View.com\u Lista.class})
//将'Views.Principal.class'替换为正确的值
公共列表列表(@JsonView(Views.Principal.class)Principal){
System.out.println(principal.getName());
返回null;
}

一些代码可以帮助我们更好地理解您所做的事情。@Lealceldero更新:DHi我使用的是springfox-swagger2版本2.9.2(Maven repository中的最新版本),但仍然没有考虑JsonView()@Yogeshhenoy版本3.0.0现在支持JsonView。
@GetMapping("/")
@PreAuthorize("hasRole('ADMINISTRADOR') or hasRole('MOTOBOY')")
@JsonView({View.Intimacao_Lista.class})
public List<Intimacao> listar(Principal principal){
    System.out.println(principal.getName());
    return null;
}
@GetMapping("/")
@PreAuthorize("hasRole('ADMINISTRADOR') or hasRole('MOTOBOY')")
@JsonView({View.Intimacao_Lista.class})
// replace `Views.Principal.class` for the proper value
public List<Intimacao> listar(@JsonView(Views.Principal.class) Principal principal){
    System.out.println(principal.getName());
    return null;
}