【发布时间】:2020-07-07 04:26:47
【问题描述】:
可以将swagger 与@JsonView 结合起来吗?我有一个模型,我使用 @JsonView 只返回几个字段,但 swagger-ui 显示了孔模型。
这是我的模型:
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;
}
这是 swagger-ui
中的结果[
{
"apresentante": {
"documento": "string",
"nome": "string"
},
"devedor": {
"bairro": "string",
"cep": "string",
"cidade": "string",
"complemento": "string",
"documento": "string",
"estado": "string",
"logradouro": "string",
"nome": "string",
"numero": "string",
"tipoLogradorouo": "string"
},
"id": 0,
"sacador": {
"chave": "string",
"documento": "string",
"especie": "string",
"nome": "string"
},
"titulo": {
"custas1": 0,
"custas2": 0,
"custas3": 0,
"custas4": 0,
"custas5": 0,
"custas6": 0,
"custas7": 0,
"custas8": 0,
"custas9": 0,
"numero": "string",
"vencimento": "string"
}
}
]
但如果我 GET 我的 API 只会返回 devedor 属性,因为 @JsonView
【问题讨论】:
-
一些代码可以帮助我们更好地理解您已经完成/正在尝试实现的目标。
-
@lealceldeiro 更新:D
标签: spring-boot swagger-ui json-view