Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jackson:Issue with bean class having multiple setters with same name and different type paramas

Tags:

java

json

jackson

json simply giving mapperException Conflicting setter definitions for property

public void setJanuary(String january) {
    try {
        setJanuary(Float.parseFloat(january));
    } catch (NumberFormatException exception) {
        setJanuary(0);
    }
}public void setJanuary(float january) {
    this.january = january;
}
like image 446
phani Avatar asked Jan 10 '23 01:01

phani


2 Answers

Problem resolved by using Annotation @JsonSetter for which setter we are using from Json

like image 138
phani Avatar answered Jan 17 '23 16:01

phani


Use the @JsonIgnore annotation on the setter methods that should be excluded.

like image 39
PNS Avatar answered Jan 17 '23 16:01

PNS