Replies: 2 comments 2 replies
-
Currently there's no way to hook into bean validation processing to handle custom annotations like I see your point regarding generators returned by the SPI not honouring bean validation annotations. This behaviour is intentional. The library does not modify user-provided generators. This is to avoid unwanted behaviour. For example, if you were to specify I think in this case, your best bet might be to get the generators.map().withKeys(withKeys.value()).minSize(...).maxSize(...); It is unfortunately a bit tedious :) Regarding using |
Beta Was this translation helpful? Give feedback.
-
@rjpipino processing custom annotations will be supported in the next release. If you have any feedback, please let me know. |
Beta Was this translation helpful? Give feedback.
-
I haven't found a good way to handle data generation for custom bean validators. Suppose I have a custom annotation
@WithKeys
that checks a map has specific keys defined. If I have a field that looks like this:In order for the map to pass the custom validator it must contain two keys:
foo
andbar
. If we were to implementInstancioServiceProvider
and set the keysThis will work except the map generated may not be valid for the other validation annotations. For example,
@Size
is ignored and map generated will contain 3 entries. I think this is a bug and the other constraint annotations should be honored.I could see a use case for supporting a post process on field generation. In this example, would be nice to have a way to provide a field predicate that determines if the field is annotated with the custom annotation and then supply a
BiConsumer
where the inputs are the generated instance and the field itself.I think this is similar to the idea with
onComplete
except the callback needs to execute on the field being generated.Anyway, hopefully this illustrates the problem I am trying solve and looking forward to some discussion on the idea. If there is a way to accomplish this with the current API please provide an example 😃
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions