【问题标题】:@JsonIgnoreProperties not working for swagger generation@JsonIgnoreProperties 不适用于招摇的一代
【发布时间】:2021-09-18 18:42:17
【问题描述】:

我试图为特定 API 端点隐藏对象的几个字段。

例如:

"student": {
    "name": "value1",
    "age": "value2",
    "dob": "value3",
    "value": "value4"
  }

我需要为某些 API 端点显示和隐藏这些值。

API 1:获取:/学校/学生/个人

"student": {
    "name": "value1",
    "age": "value2"
  }

API 2:GET : /school/student/all

"student": {
    "name": "value1",
    "age": "value2",
    "fatherName": "value3",
    "motherName": "value4",
  }

【问题讨论】:

    标签: java swagger rest springfox


    【解决方案1】:

    对我来说,您使用不同的对象,您可以创建 DTO(数据传输对象)并让您的 API 返回 DTO。

    您需要适配器将您的 domine 对象(ex.Student)转换为 DTO 对象(StudentDTO 或 TinyStudentDTO)

    EX.

    API 1: GET : /school/student/personal 应该返回 TinyStudentDTO

    TinyStudentDTO
    -name
    -age
    

    API 2: GET : /school/student/all 应该返回 StudentDTO

    您的 StudentDTO 将与 TinyStudent 一起扩展

    StudentDTO 
    -fatherName
    -motherName
    

    【讨论】:

    猜你喜欢
    • 2018-10-18
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多