Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson - JsonIgnoreProperties for parent class #998

Closed
osagie-ogbomo opened this issue Dec 10, 2021 · 1 comment · Fixed by #1033
Closed

Jackson - JsonIgnoreProperties for parent class #998

osagie-ogbomo opened this issue Dec 10, 2021 · 1 comment · Fixed by #1033
Assignees
Labels
bug Something isn't working
Milestone

Comments

@osagie-ogbomo
Copy link

Hi together,
i have a constellation which does not work as expected with JsonIgnoreProperties.

I have a REST API. One endpoint is for creating a car like POST /api/cars

Assume i have the following domain object

@Data
@SuperBuilder
@NoArgsConstructor
public class Car {
      private String id;
      private int tireCount;
      ...
}

and an api creation dto looking like

@JsonIgnoreProperties({"id"})
@Data
@SuperBuilder
@NoArgsConstructor
public class CreateCarRequest extends Car {
      ... potentially empty or carrying additional fields for car creation
}

I basically want to prevent mapping fields arround. In the dto i basically prevent Jackson from parsing not relevant fields by setting @JsonIgnoreProperties({"id"}). This works by Jackson not parsing the id field if is send it in the CreateCarRequest.

The Problem
The api doc gets generated. The description of the entity CreateCarRequest contains the field id.
It will disappear in the api doc when i add / overload the field or add it's getter + setter explicitly in CreateCarRequest. It seems like JsonIgnoreProperties does not respect parent classes and only checks for fields / getters and setters inside the current class.

Expected behaviour
@JsonIgnoreProperties({"id"}) also checks parent object fields and, if they exist, ignores them.

@osagie-ogbomo
Copy link
Author

It's working now. Thanks a lot guys! I just was able to test it recently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants