I am running spring boot application returning following sample response object:
@Getter
@Setter
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
class Response {
private String name;
private Map<String, Object> attr;
}
Now since my app is java based application,
this means that atleast one null key is allowed in Map.
So my sample response look like:
Response responseObj = someServiceMethodCall()
and response looks like:
{
"name" : "some-name",
"attr" : {
null : "some-value",
"some-key" : "other-value"
}
}
Now when I try to send this via my basic controller as response:
return ResponseEntity.ok(responseObj);
Now for this case in my postman/client I get 500 response.
Even in logs I cant see any errors from spring.
Now if this thing happen in production we cant identify simply, also enabling debug logs at spring level needs restart of system and can actually create problem.
It would be great if we have error logging around that.
I am using 2.X.X version of spring boot,
but I tested with 3.X.X also.
I debugged it, and found while doing jackson parsing to json it fails as in json NULL keys are not allowed.
But the exception is swallowed and not logged even