Replies: 1 comment
-
Since you are using a framework and not Jackson directly, these defaults are likely due to framework. So defaulting to change would be within framework in question. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Java 11
Springboot 2.7.1
Jackson 2.13.3
I have updated recently to Jackson 2.13.3. Since the update, my object's empty arrays are not serialized, they are omitted from the JSON. I have fixed it by adding @JsonInclude(Include.NON_NULL) to my property.
As mentioned in the documentation I would have expected my object to serialize with an empty array.
<<By default, Jackson does not ignore Null and Empty fields while writing JSON>>
I was wondering if this is intentional or a bug? If it is intentional, is there a global configuration to change the behavior since I have a few objects defined this way
The objects are serialized as part of an HTTP response
Example of API:
@GetMapping(value = "/customer/{customerId}", produces = {MediaType.APPLICATION_JSON_VALUE})
public CustomerModel getCustomer(@PathVariable("customerId") String customerId)
Example of object:
@Getter
@Setter
public class CustomerModel {
private String firstName;
private String lastName;
private List myObjectModels = new ArrayList<>();
}
serializes to:
"customerModel": {
"firstName": "String",
"lastName": "String"
}
instead of
"customerModel": {
"firstName": "String",
"lastName": "String",
"myObjectModels ": []
}
Fixed by:
@Getter
@Setter
public class CustomerModel {
private String firstName;
private String lastName;
}
Beta Was this translation helpful? Give feedback.
All reactions