You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change has no impact to existing code other than to ensure kiwi provides its custom validation constraints in a way that they augment custom constraints in an application. Currently, kiwi's custom constraints uses ValidationMessages.properties as its validation messages. The problem is that if an application also uses its own ValidationMessages.properties (which is generally how you implement custom constraints in a service, such as a Dropwizard application) then the application's message bundle overrides the one in kiwi unless additonal steps are taken, for example using the Maven Shade Plugin and an AppendingTransformer to combine all ValidationMessages.properties. And this assumes there are no conflicts in property names in the bundle.
This refactoring uses the method discussed in this blog to use Java's service loader mechanism. It renames the ValidationMessages.properties to ContributorValidationMessages.properties, adds a META-INF/services/jakarta.validation.ConstraintValidator file that contains the list of kiwi ConstraintValidator implementations, and removes the validatedBy from all the validation annotations (which avoids them being found twice, once via the service loader mechanism, and once via validatedBy).
Note that if there are other libraries in an application which also provide their own custom constraints and use the same ContributorValidationMessages.properties, then an additional step is still required to combine these files, e.g., using the AppendingTransformer mentioned above.
The text was updated successfully, but these errors were encountered:
* Rename ValidationMessages.properties to
ContributorValidationMessages.properties
* Add jakarta.validation.ConstraintValidator in META-INF/services
which defines the services that will be loaded via service loader
* Remove the value in the validatedBy attribute of Constraint
annotations on all kiwi custom constraints to avoid duplicate
definitions of them.
Closes#1112
* Rename ValidationMessages.properties to
ContributorValidationMessages.properties
* Add jakarta.validation.ConstraintValidator in META-INF/services
which defines the services that will be loaded via service loader
* Remove the value in the validatedBy attribute of Constraint
annotations on all kiwi custom constraints to avoid duplicate
definitions of them.
Closes#1112
For background see discussion #689 and Adding custom constraint definitions via the Java service loader.
This change has no impact to existing code other than to ensure kiwi provides its custom validation constraints in a way that they augment custom constraints in an application. Currently, kiwi's custom constraints uses
ValidationMessages.properties
as its validation messages. The problem is that if an application also uses its ownValidationMessages.properties
(which is generally how you implement custom constraints in a service, such as a Dropwizard application) then the application's message bundle overrides the one in kiwi unless additonal steps are taken, for example using the Maven Shade Plugin and anAppendingTransformer
to combine allValidationMessages.properties
. And this assumes there are no conflicts in property names in the bundle.This refactoring uses the method discussed in this blog to use Java's service loader mechanism. It renames the
ValidationMessages.properties
toContributorValidationMessages.properties
, adds aMETA-INF/services/jakarta.validation.ConstraintValidator
file that contains the list of kiwiConstraintValidator
implementations, and removes thevalidatedBy
from all the validation annotations (which avoids them being found twice, once via the service loader mechanism, and once viavalidatedBy
).Note that if there are other libraries in an application which also provide their own custom constraints and use the same
ContributorValidationMessages.properties
, then an additional step is still required to combine these files, e.g., using theAppendingTransformer
mentioned above.The text was updated successfully, but these errors were encountered: