I've:
<dependency>
<groupId>org.zalando</groupId>
<artifactId>problem-spring-web-starter</artifactId>
<version>0.27.0</version>
</dependency>
in my pom.xml, I've this DTO:
public class SomeClass {
@NotNull
private String name;
...
}
and in a @RestController:
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value="/endpoint", method = RequestMethod.POST)
public SomeClass create(@Valid @RequestBody SomeClass someClass) {
return someService.create(someClass);
}
I'm using Spring Session with header session strategy. So if I remove X-Auth-Token header, I get an empty response body.
If I remove Problem Spring dependency, I get:
{
"timestamp": 1640094286096,
"status": 403,
"error": "Forbidden",
"message": "Access Denied",
"path": "/endpoint"
}
and for validations, regardless Spring Problem is in my pom.xml/classpath, I get Spring's default validation exception:
{
"timestamp": 1640093786923,
"status": 400,
"error": "Bad Request",
"errors": [
{
"codes": [
"NotNull.someClass.name",
"NotNull.name",
"NotNull.java.lang.String",
"NotNull"
],
"arguments": [
{
"codes": [
"someClass.name",
"name"
],
"arguments": null,
"defaultMessage": "name",
"code": "name"
}
],
"defaultMessage": "must not be null",
"objectName": "someClass",
"field": "name",
"rejectedValue": null,
"bindingFailure": false,
"code": "NotNull"
}
],
"message": "Validation failed for object='someClass'. Error count: 1",
"path": "/endpoint"
}
How do I make Problem Spring kick in for both cases?
Update:
I've verified that ProblemModule and ConstraintViolationProblemModule are configured, but regardless DefaultHandlerExceptionResolver is called upon HTTP 400 exceptions. When ErrorMvcAutoConfiguration is excluded, the only change is that the response body becomes HTML rather than JSON. I have several Jackson2ObjectMapperBuilderCustomizer beans, tried excluding them to no extent.
Furthermore, creating a class such as:
@ControllerAdvice
public class SampleControllerAdvice implements MethodArgumentNotValidAdviceTrait {
}
resolves the issue for constraint violation cases.