JSON Post request for boolean field sends false by default

Remember that Jackson, by default, determines the property name from either the getter or setter (the first that matches).

To deserialize an object of type POJOUserDetails, Jackson will look for three properties

public void setFirstName(String firstName) {

public void setLastName(String lastName) {

public void setActive(boolean isActive) {

in the JSON. These are basically firstName, lastName, active.

You get the following JSON

{ "firstName": "Test", "lastName": "1", "isActive": 1 }

So firstName and lastName are mapped, but you don’t have a property named isActive.

Jackson depends on Java Bean naming conventions with their accessors (getters) and mutators (setters). For a field like

private boolean isActive;

the appropriate setter/getter names are

public boolean getIsActive() {
    return isActive;
}

public void setIsActive(boolean isActive) {
    this.isActive = isActive;
}

So you have two possible solutions. Change your getter/setter as shown above or annotate your field with @JsonProperty so that Jackson uses the field name to determine the property name

@JsonProperty
private boolean isActive;

Leave a Comment