Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a customizable FieldError creation at SpringValidatorAdapter [SPR-12819] #17416

Closed
spring-issuemaster opened this issue Mar 15, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Mar 15, 2015

Kazuki Shimizu opened SPR-12819 and commented

I want to customize a FieldError creation processing.
In production environment of my application, a part of rejected value need exclude from toString method. (e.g. password, credit card number etc. )
(But in development and test environment, all of rejected values require for the debugging.)

e.g. )
Specifically, i want to extract as protected method.

protected FieldError createFieldError(
		String objectName, String field, Object rejectedValue,
		String[] codes, Object[] arguments, ConstraintViolation<Object> violation) {
	return new FieldError(objectName, field, rejectedValue, false,
			codes, arguments, violation.getMessage());
}

I will submit a pull request later.


Affects: 4.1.5

Referenced from: pull request #756

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 15, 2015

Kazuki Shimizu commented

I submitted a pull request.
Please review.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 16, 2015

Juergen Hoeller commented

Reviewing the use case here, I'm in the process of extracting a protected getInvalidValue method instead. We have getArgumentsForConstraint along those lines already. Such specific methods are arguably nicer to use, and we don't expose FieldError creation methods in similar places either (DefaultBindingErrorProcessor, AbstractBindingResult).

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 16, 2015

Juergen Hoeller commented

I've introduced protected determineField, determineErrorCode and getRejectedValue methods for fine-grained control over the reported field error - without having to instantiate FieldError objects directly.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.