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

Swagger does not respect Jackson @JsonIgnoreProperties annotation #2613

Closed
guan25 opened this issue Aug 13, 2018 · 12 comments
Closed

Swagger does not respect Jackson @JsonIgnoreProperties annotation #2613

guan25 opened this issue Aug 13, 2018 · 12 comments
Labels
Milestone

Comments

@guan25
Copy link

guan25 commented Aug 13, 2018

When I used @JsonIgnoreProperties annotation to ignore some redundant properties from the super classes, it has completely no effect on Swagger. The consequence is the API document and the real Json objects have inconsistent structure. Does anyone know how we can solve this problem?

@JsonIgnoreProperties(value = {"houseNo","coNo","coName","reviewer","latelyMonthLookTimes"
,"reviewTime"})
public class SecondHouseBrokerInVo extends SecondHouseVo {

}

@dilipkrish dilipkrish added the bug label Aug 13, 2018
@dilipkrish
Copy link
Member

This is a known issue

@RodolpheGohard
Copy link

Hello, it seems the issue is still there (see also #113)

Any plan of fixing it ? or any workarounds ?

@jmformenti
Copy link

In some cases a workaround for this issue is overload the getter of parent property and use @JsonIgnore, i.e:

@JsonIgnore
public Links getLinks() {
  return super.getLinks();
}

@florian-forestier
Copy link

florian-forestier commented May 14, 2020

Hi,

I currently have this problem on my project. This is insane, because some of my objects are linked to another objects, and so on. My scheme is completely wrong due to this problem... Is there any workaround for this ? Or, at least, a way to tell Springfox to do not go further than one or two "indirection" level ?

@svpr3m0
Copy link

svpr3m0 commented Jul 6, 2020

@dilipkrish Could this issue be addressed at some moment in the 3.x line? I've run into this problem a lot of times in the last 5 years so it'd be great if it could be fixed.

@florian-forestier
Copy link

Hi @svpr3m0. I agree that it would be great to fix this issue. Howewer, i've found a workaround, using JsonView (which is supported in 3.0.0 SNAPSHOT - see #3333) instead of JsonIgnoreProperties.

This modification implies some changes on the code, but are mainly limited to annotations. :)

@svpr3m0
Copy link

svpr3m0 commented Jul 6, 2020

@Artheriom Thanks for the suggestion, but it won't help in my case. I need to ignore the suppressed property that is inherited in my DepartmentNotFoundExceptionwhen extending Exception/RuntimeException:

    @ApiOperation(value = "Create department")
    @ApiResponses({
            ...
            @ApiResponse(code = 404, message = "Error de validación", response = DepartmentNotFoundException.class),
            ...
    })
    @GetMapping(value = "/v1/department/{id}", produces = MediaType.APPLICATION_JSON_VALUE)

Since getSuppressed is final I can't override that method to place a @JsonIgnore annotation on the getter. That's where @JsonIgnoreProperties would come in handy.

    public final synchronized Throwable[] getSuppressed() {

@Jojoooo1
Copy link

Jojoooo1 commented Jul 8, 2020

still no solution ?

@dilipkrish dilipkrish added this to the 3.0 milestone Jul 8, 2020
@dilipkrish
Copy link
Member

@Jojoooo1 will try and see if I can fix

@manucr619
Copy link

is this issue Fixed ? any updates on this ?

@Kiran-N
Copy link

Kiran-N commented Nov 15, 2021

Tried with 3.0.0 release but not working.

@jennyadobreva
Copy link

jennyadobreva commented Apr 13, 2022

Use <templateResourcePath> option in the configuration.
I added a fix to my code, extracting the oneof_interface.mustache and adding the following lines:
{{#jackson}}
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

{{/jackson}}
after the first line and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants