【问题标题】:How to exclude properties from schemas using @JsonView如何使用 @JsonView 从模式中排除属性
【发布时间】:2021-11-27 21:12:01
【问题描述】:

在 Spring 中,当控制器方法使用 @JsonView 注释时,它只返回 遵守配置的对象的相应注释属性 spring.jackson.mapper.default-view-inclusion,默认为false。

// Kotlin code

abstract class Base {
    lateinit var transientInternalProperty: String
}

class Main(val externalProperty: String) : Base()

@RestController
@RequestMapping("/")
class MainController {

    @JsonView(Views.Public::class)
    @GetMapping("/")
    fun index() = Main()
}

以上面的例子,如何在生成的时候排除非注解的属性 Main_Public 架构。如何将transientInternalProperty 排除在 Main_Public 之外而无需对其进行注释?

我在文档中找不到任何关于此的内容。只需this small section。

我尝试用 @JsonView 注释类本身以指示属性的“默认视图”,但它不起作用。

【问题讨论】:

    标签: springdoc


    【解决方案1】:

    要从生成的 OpenAPI sepc 中排除属性:更喜欢 swagger-annotation,@Hidden 或 @Schema(hidden = true))。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 2016-03-30
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      相关资源
      最近更新 更多