- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
可以将 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;
}
这是我的 Controller :
@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
最佳答案
It's possible to integrate the swagger with
@JsonView
?
是的(部分)。
此后pull request已合并,您可以将其用于:
响应对象(您已使该部分正常工作)。
@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;
}
RequestBody 对象(还没有,拉取请求正在路上,请参阅 #2918 和 comment at #2079 中的示例)。对于您的情况:
@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;
}
关于spring-boot - Springboot swagger 与 JsonView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60868941/
我使用自定义反序列化器,但是当我调用objectMapper.writerWithView(Views.MyView.class)时,我没有得到预期的结果。 在调试的时候,我发现在方法中 public
我有包装 JPA 实体的 UI 对象,并且在该 UI 对象的构造函数中,我对某些属性进行了延迟加载。在同一个构造函数中,我需要知道 JsonView 当前处于事件状态,因此我不会延迟加载一些不需要的字
我需要使用@JsonView 在反序列化时抛出异常。 我的 POJO: public class Contact { @JsonView( ContactViews.Person.class
以下内容将仅包含具有 JsonView(View.MyView.class) 注释的字段: @JsonView(View.MyView.class) @RequestMapping(value = "
我无法使用@JsonView 执行这个简单的示例。我做错了什么? ${jackson-2-version} = 2.6.5 com.fasterxml.jackson.core ja
我正在尝试使用 @JsonView 注释从 Spring 中的对象反序列化多个字段。但是,我将注释添加到我的方法中,它没有反序列化指定的字段,而是返回一个空对象。 这是我的 POJO: @Entity
我正在尝试为我的嵌套实体使用 @JsonView 注释。更清楚地说,假设我们有 2 个实体,每个实体都有自己的 View 类。 public class JsonViewAddress {
我有以下测试设置: public class TestingPojo { public int getA() { return 1; } @JsonView(T
我试图根据请求用户的角色有选择地隐藏响应中的某些字段。据我所知,来自 Jackson 的 JsonView 可能是正确的选择。 我需要能够显示所有字段,除非它们已标记有特定的访问级别。我为访问级别创建
我的一个类有 3 个相同类型的属性。现在我正在尝试将其序列化为 JSON,但其中一个属性需要以不同的方式序列化 - 基本上这些属性之一是“内部”,我只需要它的 id,其余属性必须完全序列化。 到目前为
我将 Jackson JSON 1.9.12 与 SpringMVC 一起使用。我创建了一个带有 JSON 字段的 dto。我想要两个具有不同 JSON 字段的相同 dto 配置文件,因此我创建了两个
jackson 2.2.2 ObjectMapper mapper = new ObjectMapper(); mapper.getSerializationConfig().withView(Vie
如何在不在该 Java 对象的每个字段上指定 @JsonView 的情况下将 Java 对象的所有字段包含到 JSON 响应( View )中? 编辑:我需要在不使用另一个外部库的情况下实现这一点。
我有类似于这两个类的东西: public class User { @JsonView(UserView.IdOnly.class) int userID; String na
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在开发一个 Spring boot(MVC、JPA)应用程序,它需要在不同的请求上返回不同的属性。我找到了 @JsonView 注释,它似乎有效。但是我需要用基本 View 来注释每个属性吗? 示
您好,我几乎没有相互嵌入的 UI 对象。示例 #1: class CarUI { public UserUI user; public UserUI agent; .... publi
我正在使用新的 CakePHP 2.1,并希望使用 JsonView 使我的 Controller 响应 JQuery 在客户端创建的 ajax 请求。但是,根据文档,这应该使用 JsonView 自
Spring 从 4.1 版本开始支持 @JsonView。 使用具有多个标识符的 @JsonView 注释 Spring Controller 的(使用 @RestController 注释)方法我
我有一个类包含另一个类的集合。 class A{ @JsonView(VerboseViewA.Minimal.class) String field1; @JsonView(VerboseVi
我是一名优秀的程序员,十分优秀!