Skip to content

Allow re-initialization of DataBinder to and from direct field or bean property access #24347

@vghero

Description

@vghero

Affects: Spring 5.0.9 / Boot 2.0.5

We have a Spring Web Mvc REST service implemented using complex nested DTO models which are validated using @Valid on controller method signatures. We created a global RestControllerAdvice which uses @InitBinder to set it to direct field access. This seems to work as expected.

Now we have one controller, that has to deal with bean property style models and needs a different InitBinder setup. Having the hope of being able to override the global default one, by specifying it on the special controller itself, sadly failed with an error message of the InitBinder about an already initialized binding. Also there does not seem to exist some kind of exclude parameter on RestControllerAdvice that would allow us to exclude that special controller.
Trying to use a special annotation on the other controllers and specifying it via annotations parameter on RestControllerAdvice also didn't work out during Mock Mvc Tests - ignoring the global one.

Finally, we ended up specifying @InitBinder on each controller separately - which works in all cases, but is quite cumbersome. Since we want to define the default globally and transparently for all controllers. Without having to remember, to specify packages, controller classes etc. on the global controller advice for new controllers to work properly - e.g. during validation.

Are there any plans to add some kind of exclude to the advice or being able to override a global default on controller level? This would be very helpful.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions