Hi,
I've been working on a module to integrate Bean Validation with Jackson:
https://github.com/kewne/jackson-validation
The basic ideas are:
1. Without integrating validation into `@JsonCreator` calls, you can't then
enforce invariants in class instances, e.g. this.name =
Objects.requireNonNull(name);
with validation support, you can annotate params with @NotNull.
2. Bean Validation inspects the class and knows nothing about Jackson, so
it generates paths using the Java definition;
with this module , you would be able to declare @JsonProperty("abc") String
name and get violation paths with the correct names (instead of "name").
My approach so far has been to create my own value instantiator and perform
validations before and after instantiation, but this fails because, if an
object deep in the tree fails its validation, I don't know how to catch it
so it shows up properly in violations tree:
class Root {
private Nested nested;
}
class Nested {
@NotNull private String name;
}
ObjectMapper.readValue("""
{
"nested": {}
}
""", Root.class); //throws validation exception with Nested as root...
Any hints on how I might handle the nesting?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/aadb6051-bcdb-4a20-bd5b-8cd8751efe8an%40googlegroups.com.