I have a swaggerized Spring MVC endpoint for a POST operation. The operation takes a path param and a (json) request entity. When the swagger UI is generated, it automatically creates an example value of the request body data type. This example is based on a java entity in the application. The entity is used for some other operations, however for the POST operation, I do not want some of the entity fields exposed in the example. Is it possible to modify this example without modifying the existing java model? For example, is it possible to exclude in the below example lastUpdate
.
Asked
Active
Viewed 2,612 times
4

Community
- 1
- 1

user1491636
- 2,355
- 11
- 44
- 71
-
try this http://stackoverflow.com/a/27779319/1754020 – Eddie Martinez Feb 27 '17 at 21:37
1 Answers
2
Yes it is possible to ignore lastUpdate
in the example value using jackson annotations JsonIgnore
.
import com.fasterxml.jackson.annotation.JsonIgnore;
public class Phone {
private String phoneNumber;
private String lastUpdate;
private int status;
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@JsonIgnore
public String getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate() {
this.lastUpdate = lastUpdate;
}
public int getStatus() {
return lastUpdate;
}
public void setStatus() {
this.status = status;
}
}

Grammin
- 11,808
- 22
- 80
- 138
-
1Adding `@JsonIgnore` would also remove it from responses in other operations - which is not what I'm trying to achieve. I just want to hide it from the swagger. – user1491636 Apr 25 '18 at 18:33
-
Response and Request should be separate classes in your architecture if you don't want their settings cohesion. – Zon Mar 06 '20 at 08:43
-
Doesn't work when annotated either on field or on getter - disappears from the Model as well. This way it works the same as Swagger's "hidden" property. – Zon Mar 06 '20 at 09:03