# Generic field validation

**URL:** <https://discourse.hibernate.org/t/generic-field-validation/2082>\
**Category:** Hibernate Validator\
**Created:** [January 18, 2019, 1:57pm UTC](https://discourse.hibernate.org/t/generic-field-validation/2082 "2019-01-18T13:57:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_rollinger](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@thomas\_rollinger](https://discourse.hibernate.org/u/thomas_rollinger)\
**Post date:** [January 18, 2019, 1:57pm UTC](https://discourse.hibernate.org/t/generic-field-validation/2082/1 "2019-01-18T13:57:07Z")

</div>

I want to apply a constraint on all string property of an object, but with the programmatic api as I don’t want to annotate all property.

```auto
class Foo {

   String value1;
   Integer value2;
   @Valid
   Bar value3;
}

class Bar {
    String value4;
    Boolean value5;
}

```

Here if I validate the object Foo, I would like to have the properties value1 and value4 to be validated with my constraint. I tried the following but I cannot specify wild card for fields.

```auto
ConstraintMapping constraintMapping = hibernateValidatorConfiguration.createConstraintMapping();
constraintMapping
                    .type(Object.class)
                    .property("*", ElementType.FIELD)
                    .type(String.class)
                    .constraint( new GenericConstraintDef<>(MyConstraint.class));
hibernateValidatorConfiguration.addMapping(constraintMapping);

```

I think that I am looking to some property selector feature that I dont find.

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [January 18, 2019, 2:14pm UTC](https://discourse.hibernate.org/t/generic-field-validation/2082/2 "2019-01-18T14:14:13Z")

</div>

We don’t have something built-in in HV.

You can simply use the standard Java reflection API to get the fields of your class and iterate on them.
