Recently, I met another interesting twist on this issue. We started using the Hibernate5Module to help with some lazy loading problems. In addition, we use Groovy, so we do not define getters and setters.
It turns out that the Hibernate module seems to be interfering with the @JsonProperty annotation. In particular, if you have something annotated with @Transient So, if you have something like:
@Transient @ApiModelProperty(required = true) @JsonProperty("alternateName") String property
You will not see alternateName in JSON. In addition, your customers are likely to have problems with their POST and PUT! To fix this, you can use a simple workaround. Define getters and setters for the internal name you need to use (*), and do not use the value attribute on @JsonProperty . So this works:
@Transient @ApiModelProperty(required = true) @JsonProperty String alternateName void setProperty(String property) { this.alternateName = property } @JsonIgnore String getProperty() { this.alternateName }
Note the use of @JsonIgnore on the getter. If you do not, your infrastructure will most likely pick it up and you will have duplicate entries for the same thing in your JSON.
In any case - I hope this helps someone!
(*) We tried to stick to a specific interface, thereby applying the internal name. However, the open API requires a different, user-friendly name.
source share