baskaran
baskaran

Reputation: 11

Why is my boolean field still showing up as part of the request body after I used @JsonIgnore and @JsonIgnoreProperties?

In my Swagger documentation, for POST requests, it should not show the boolean field in the request body.

I want to ignore the booleanValue field in the DTO class below:

public class MyDto {
    private String stringValue;
    @JsonIgnore
    private int intValue;
    private boolean booleanValue;
}

I have tried using @JsonIgnore and @JsonIgnoreProperties, but it is not working.

1.  @JsonIgnore
    private boolean booleanValue;

2.  @JsonIgnoreProperties(value = { "booleanValue"})
    public class MyDto {
      /* ... */
    }

How can I ignore the boolean field in the MyDto class?

Upvotes: 1

Views: 2112

Answers (3)

Palak
Palak

Reputation: 11

You will need to change dataType from boolean to Boolean, then it will work. Thanks

Upvotes: 1

Rajan
Rajan

Reputation: 49

is your boolean field starts with isSomething or hasSomething? if yes, then the @Jsonignore doesn't work on it. you need to change it to "something"

Upvotes: 1

cassiomolin
cassiomolin

Reputation: 130937

Use @ApiModelProperty and set the hidden element to true:

@ApiModelProperty(hidden = true)
private boolean booleanValue;

Upvotes: 0

Related Questions