property declaration is
private Boolean isActive;
but json reads only
"active": true
ChatGPT zei:
Ah — you've hit a common JSON mapping issue in Java!
🧠 Problem:
Your property in the class is named:
java
private Boolean isActive;
But your JSON is sending:
json
"active": true
By default, most serializers/deserializers (like Jackson, used in Spring Boot) map the field name based on the JavaBean getter/setter. In your case:
java
public Boolean getActive() {
return isActive;
}
public void setActive(Boolean active) {
isActive = active;
}
Because the method is named getActive() (not getIsActive()), Jackson expects the JSON key to be active, not isActive — which is why the JSON works only if it's active, not isActive.
✅ Best Practice: Rename the field
To avoid confusion and be consistent, change your field to:
java
private Boolean active;
Then everything aligns naturally:
Field name: active
JSON key: "active"
Getter/setter: getActive() / setActive(Boolean)
🚫 If you must keep isActive as the field name
You can use Jackson annotations to map it explicitly:
java
@JsonProperty("active")
private Boolean isActive;
But this adds unnecessary complexity if you're not relying on isX naming for semantic reasons.
✅ Recommendation:
Rename your field to active, unless there's a strong reason to keep isActive.
Top comments (0)