Different @JsonSetter vs @JsonGetter breaks Swagger example model
See original GitHub issueSwagger version 2.7.0 Java 1.8.0
I currently have an API mapping:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public List<TestObject> reportsTest() {
return new ArrayList<>();
}
and TestObject is defined as:
public class TestObject {
private String var1;
public TestObject() {
}
@JsonGetter("var")
public String getVar1() {
return var1;
}
@JsonSetter("var")
public void setVar1(String var1) {
this.var1 = var1;
}
}
Everything works as expected, the Swagger UI docs example model looks good:
Now, if I change the @JsonGetter to something else (not matching the @JsonSetter) because I want the serialization to be mapped differently than the input like so:
public class TestObject {
private String var1;
public TestObject() {
}
@JsonGetter("var")
public String getVar1() {
return var1;
}
@JsonSetter("newvar") // <-- change made here
public void setVar1(String var1) {
this.var1 = var1;
}
}
The example model no longer works and I’m stuck with this:
Is there a workaround for this? I’ve tried setting @JsonProperty on the variable definition but that didn’t work either…
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Jackson Not Overriding Getter with @JsonProperty
The issue was when deserializing the JSON response from our DB into Java class object, our code didn't have @JsonSetter on the class'...
Read more >Jackson JSON - Using @JsonProperty, @JsonSetter and ...
Following example shows how to use @JsonProperty annotation to rename properties. This annotation can be used on fields or getters or setters.
Read more >com.fasterxml.jackson.annotation.JsonSetter.value java code ...
public static String propertyName(Method method) { Optional<JsonGetter> jsonGetterAnnotation ... origin: com.mangofactory/swagger-models ...
Read more >Overview (Apache Juneau 8.2.0)
org.apache.juneau.dto.swagger.ui ... Examples. org.apache.juneau.examples.core.json. Examples ... Non-Tree Models and Recursion Detection.
Read more >About @JsonProperty, @JsonGetter and @JsonSetter
And that only has @JsonProperty on the getters, what is supposed to be the expected serialization/deserialization behaviour? What about:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try this un use @JsonGetter only @JsonSetter
Hello , I am also facing the same issue. Can you please let me know if the fix has been release?
Thanks, Saravanan