0

I'm Using Spring Boot, Jersey, and Swagger (io.swagger:swagger-jersey2-jaxrs:1.5.8)

I have a JSON response I'm returning as a response to a GET, lets say it's like this:

{"myText": "success"}

However, I want to be able to customize the attributes in the response to be different than their underlying java respresentation, e.g.

{"My Own Text": "success"}

I can't use "My Own Text" as a Java class attribute, so I store it as myText, but I'd like to expose it to clients in a more "friendly" format. I've tried using ApiModelProperty(name="My Own Text"). That changes the Model that displays in the Swagger Documentation, but the response still comes back as "myText".

I'd like to do something similar with PUTs as well. Is the solution to provide another service that does a dictionary mapping of unfriendlyAttribute-to-friendlyAttribute?

Derek
  • 21,828
  • 7
  • 53
  • 61

1 Answers1

2

You should use JsonProperty on the getter of myText:

  @JsonProperty("My Own Text")

used to indicate external property name,

Ori Marko
  • 56,308
  • 23
  • 131
  • 233