Explore the idea of attaching custom details to ConstraintViolation #34
Labels
core
The core of the library is involved
DSL
API design and its DSL
enhancement
New feature or request
The
ConstraintViolation
haspath
andmessage
, which is sufficient for most cases.But it is not the most straightforward design if I need to pinpoint on the exact constraint being violated and act on it. For instance, to pick out a particular constraint violation and throw an alternate Exception instead of the generic Exception.
Currently, to workaround this limitation, there are possibly two ways:
path
using thewithPath { absolute("some_identifier") }
DSLmessage
using theotherwise { "some_identifier" }
DSLThe first workaround loses the
path
in a meaningful way. And the second workaround loses human readable messages.Is it possible to add a third field of
metadata: Map<String, Any>
toConstraintViolation
, so that user can freely attach whatever metadata they need to the violation instance.Possible DSL design:
Then, when analyzing the
ConstraintViolation
:The text was updated successfully, but these errors were encountered: