0

I cannot find a way to fix this issue, but... maybe it's not an issue.

I use Extjs as the front-end and Spring MVC as backend, the Ajax request looks like:

{"isOk": true}

The Mapping DTO is:

public class TestDTO implements Serializable {

    private static final long serialVersionUID = -6074462313103219627L;

    private Boolean isOK;
    public Boolean isOk(){...}
    Public void setOk(Boolean isOk){...}
}

The get/set method be generated by intellij idea, as you can imagine that jackson works fine if I add @JsonProperty("isOk") under the "setOk" method.

But I have a lot of ***DTO objects, so is there a convenient method to reslove this issue? thanks.


I have checked the "com.fasterxml.jackson.databind.SerializationFeature" class, and didn't find any config which like the "compatible_boolean_and_ignore_is_keyword" etc..

Sam.Wang
  • 21
  • 2

2 Answers2

1

I didn't test it, but might be helpful for your case:

https://stackoverflow.com/a/35088196/677937

Basically, try to rename your getter/setter to:

getIsOk / setIsOk

It should then serialize/deserialize json in form of {"isOk": ... }

Stanislau
  • 402
  • 1
  • 5
  • 16
  • Yes, it is work! but I need modify a lot of pojo objects, that is the reason. – Sam.Wang Sep 28 '18 at 08:29
  • Yes, I understand it. From this perspective, there is no difference for you in either adding @JsonProperty or renaming setters/getters in all the POJOs. The underlying issue here is a naming convention of the JSON you work with. If it's under your control - then it would be simpler just update it to something like {"ok": true}. If not - then only choice you have is to modify the POJOs in one or another way – Stanislau Sep 28 '18 at 08:37
  • I get you mean, I just want to get a way what can balance the generate mechanism & jackson mapping rule. As you know, most developers like to use intellij idea to generate getter/setter methods, and they easily ignore the issue until debugging from frontend to backend. – Sam.Wang Sep 28 '18 at 09:18
0

It's been some time since I used spring, but if I recall correctly you have to

  • annotate the class with @Entity
  • implement the Serializable interface (class DTO implements Serializable)
  • provide a default constructor
  • I edit my question, the point is that the filed name starts with "is", so the mapping function is not work. – Sam.Wang Sep 28 '18 at 08:27