Skip to content

Commit 3a1944c

Browse files
committed
HV-1623 Stop the propagation of JavaBeanField/Getter
We don't need the elements to be typed so let's be looser to open the gate for JSON properties (which will probably simply be treated as fields).
1 parent e5b7c8d commit 3a1944c

9 files changed

+34
-28
lines changed

engine/src/main/java/org/hibernate/validator/internal/cfg/context/ConfiguredConstraint.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.validator.internal.metadata.location.ConstraintLocation;
2222
import org.hibernate.validator.internal.properties.Callable;
2323
import org.hibernate.validator.internal.properties.javabean.JavaBeanField;
24+
import org.hibernate.validator.internal.properties.javabean.JavaBeanGetter;
2425
import org.hibernate.validator.internal.util.annotation.AnnotationDescriptor;
2526
import org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor;
2627
import org.hibernate.validator.internal.util.logging.Log;
@@ -53,10 +54,14 @@ static <A extends Annotation> ConfiguredConstraint<A> forType(ConstraintDef<?, A
5354
return new ConfiguredConstraint<>( constraint, ConstraintLocation.forClass( beanType ) );
5455
}
5556

56-
static <A extends Annotation> ConfiguredConstraint<A> forFieldProperty(ConstraintDef<?, A> constraint, JavaBeanField javaBeanField) {
57+
static <A extends Annotation> ConfiguredConstraint<A> forField(ConstraintDef<?, A> constraint, JavaBeanField javaBeanField) {
5758
return new ConfiguredConstraint<>( constraint, ConstraintLocation.forField( javaBeanField ) );
5859
}
5960

61+
static <A extends Annotation> ConfiguredConstraint<A> forGetter(ConstraintDef<?, A> constraint, JavaBeanGetter javaBeanGetter) {
62+
return forExecutable( constraint, javaBeanGetter );
63+
}
64+
6065
public static <A extends Annotation> ConfiguredConstraint<A> forParameter(ConstraintDef<?, A> constraint, Callable callable, int parameterIndex) {
6166
return new ConfiguredConstraint<>( constraint, ConstraintLocation.forParameter( callable, parameterIndex ) );
6267
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
*
2626
* @author Marko Bekhta
2727
*/
28-
final class FieldPropertyConstraintMappingContextImpl extends PropertyConstraintMappingContextImpl<JavaBeanField> {
28+
final class FieldConstraintMappingContextImpl extends PropertyConstraintMappingContextImpl<JavaBeanField> {
2929

30-
FieldPropertyConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, JavaBeanField javaBeanField) {
30+
FieldConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, JavaBeanField javaBeanField) {
3131
super( typeContext, javaBeanField, ConstraintLocation.forField( javaBeanField ) );
3232
}
3333

3434
@Override
3535
public PropertyConstraintMappingContext constraint(ConstraintDef<?, ?> definition) {
3636
super.addConstraint(
37-
ConfiguredConstraint.forFieldProperty(
37+
ConfiguredConstraint.forField(
3838
definition, getProperty()
3939
)
4040
);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
*
2525
* @author Marko Bekhta
2626
*/
27-
final class GetterPropertyConstraintMappingContextImpl extends PropertyConstraintMappingContextImpl<JavaBeanGetter> {
27+
final class GetterConstraintMappingContextImpl extends PropertyConstraintMappingContextImpl<JavaBeanGetter> {
2828

29-
GetterPropertyConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, JavaBeanGetter javaBeanGetter) {
29+
GetterConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, JavaBeanGetter javaBeanGetter) {
3030
super( typeContext, javaBeanGetter, ConstraintLocation.forGetter( javaBeanGetter ) );
3131
}
3232

3333
@Override
3434
public PropertyConstraintMappingContext constraint(ConstraintDef<?, ?> definition) {
3535
super.addConstraint(
36-
ConfiguredConstraint.forExecutable(
36+
ConfiguredConstraint.forGetter(
3737
definition, getProperty()
3838
)
3939
);

engine/src/main/java/org/hibernate/validator/internal/cfg/context/TypeConstraintMappingContextImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public PropertyConstraintMappingContext field(String property) {
146146
throw LOG.getPropertyHasAlreadyBeConfiguredViaProgrammaticApiException( beanClass, property );
147147
}
148148

149-
PropertyConstraintMappingContextImpl context = new FieldPropertyConstraintMappingContextImpl( this, javaBeanField );
149+
PropertyConstraintMappingContextImpl context = new FieldConstraintMappingContextImpl( this, javaBeanField );
150150
configuredMembers.add( javaBeanField );
151151
propertyContexts.add( context );
152152
return context;
@@ -166,7 +166,7 @@ public PropertyConstraintMappingContext getter(String property) {
166166
throw LOG.getPropertyHasAlreadyBeConfiguredViaProgrammaticApiException( beanClass, property );
167167
}
168168

169-
PropertyConstraintMappingContextImpl context = new GetterPropertyConstraintMappingContextImpl( this, javaBeanGetter );
169+
PropertyConstraintMappingContextImpl context = new GetterConstraintMappingContextImpl( this, javaBeanGetter );
170170
configuredMembers.add( javaBeanGetter );
171171
propertyContexts.add( context );
172172
return context;

engine/src/main/java/org/hibernate/validator/internal/metadata/aggregated/PropertyMetaData.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.hibernate.validator.internal.metadata.descriptor.PropertyDescriptorImpl;
3030
import org.hibernate.validator.internal.metadata.facets.Cascadable;
3131
import org.hibernate.validator.internal.metadata.location.ConstraintLocation;
32-
import org.hibernate.validator.internal.metadata.location.GetterPropertyConstraintLocation;
32+
import org.hibernate.validator.internal.metadata.location.GetterConstraintLocation;
3333
import org.hibernate.validator.internal.metadata.location.TypeArgumentConstraintLocation;
3434
import org.hibernate.validator.internal.metadata.raw.ConstrainedElement;
3535
import org.hibernate.validator.internal.metadata.raw.ConstrainedElement.ConstrainedElementKind;
@@ -234,7 +234,8 @@ protected Set<MetaConstraint<?>> adaptConstraints(ConstrainedElement constrained
234234
return constraints;
235235
}
236236

237-
ConstraintLocation getterConstraintLocation = ConstraintLocation.forGetter( ( (ConstrainedExecutable) constrainedElement ).getCallable().as( JavaBeanGetter.class ) );
237+
ConstraintLocation getterConstraintLocation = ConstraintLocation
238+
.forGetter( ( (ConstrainedExecutable) constrainedElement ).getCallable().as( JavaBeanGetter.class ) );
238239

239240
// convert return value locations into getter locations for usage within this meta-data
240241
return constraints.stream()
@@ -248,7 +249,7 @@ private MetaConstraint<?> withGetterLocation(ConstraintLocation getterConstraint
248249
// fast track if it's a regular constraint
249250
if ( !( constraint.getLocation() instanceof TypeArgumentConstraintLocation ) ) {
250251
// Change the constraint location to a GetterConstraintLocation if it is not already one
251-
if ( constraint.getLocation() instanceof GetterPropertyConstraintLocation ) {
252+
if ( constraint.getLocation() instanceof GetterConstraintLocation ) {
252253
converted = constraint.getLocation();
253254
}
254255
else {
@@ -275,7 +276,7 @@ private MetaConstraint<?> withGetterLocation(ConstraintLocation getterConstraint
275276
for ( ConstraintLocation location : locationStack ) {
276277
if ( !(location instanceof TypeArgumentConstraintLocation) ) {
277278
// Change the constraint location to a GetterConstraintLocation if it is not already one
278-
if ( location instanceof GetterPropertyConstraintLocation ) {
279+
if ( location instanceof GetterConstraintLocation ) {
279280
converted = location;
280281
}
281282
else {

engine/src/main/java/org/hibernate/validator/internal/metadata/location/ConstraintLocation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ static ConstraintLocation forClass(Class<?> declaringClass) {
4343
}
4444

4545
static ConstraintLocation forField(JavaBeanField field) {
46-
return new FieldPropertyConstraintLocation( field );
46+
return new FieldConstraintLocation( field );
4747
}
4848

4949
static ConstraintLocation forGetter(JavaBeanGetter getter) {
50-
return new GetterPropertyConstraintLocation( getter );
50+
return new GetterConstraintLocation( getter );
5151
}
5252

5353
static ConstraintLocation forTypeArgument(ConstraintLocation delegate, TypeVariable<?> typeParameter, Type typeOfAnnotatedElement) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
*/
77
package org.hibernate.validator.internal.metadata.location;
88

9-
import org.hibernate.validator.internal.properties.javabean.JavaBeanField;
9+
import org.hibernate.validator.internal.properties.Property;
1010

1111
/**
1212
* Field property constraint location.
1313
*
1414
* @author Marko Bekhta
1515
*/
16-
public class FieldPropertyConstraintLocation extends PropertyConstraintLocation<JavaBeanField> {
16+
public class FieldConstraintLocation extends PropertyConstraintLocation {
1717

18-
FieldPropertyConstraintLocation(JavaBeanField javaBeanGetter) {
19-
super( javaBeanGetter );
18+
FieldConstraintLocation(Property field) {
19+
super( field );
2020
}
2121

2222
@Override
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
*/
77
package org.hibernate.validator.internal.metadata.location;
88

9-
import org.hibernate.validator.internal.properties.javabean.JavaBeanGetter;
9+
import org.hibernate.validator.internal.properties.Property;
1010

1111
/**
1212
* Getter property constraint location.
1313
*
1414
* @author Marko Bekhta
1515
*/
16-
public class GetterPropertyConstraintLocation extends PropertyConstraintLocation<JavaBeanGetter> {
16+
public class GetterConstraintLocation extends PropertyConstraintLocation {
1717

18-
GetterPropertyConstraintLocation(JavaBeanGetter javaBeanGetter) {
19-
super( javaBeanGetter );
18+
GetterConstraintLocation(Property getter) {
19+
super( getter );
2020
}
2121

2222
@Override

engine/src/main/java/org/hibernate/validator/internal/metadata/location/PropertyConstraintLocation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
* @author Marko Bekhta
1919
* @author Guillaume Smet
2020
*/
21-
public abstract class PropertyConstraintLocation<T extends Property> implements ConstraintLocation {
21+
public abstract class PropertyConstraintLocation implements ConstraintLocation {
2222

2323
/**
2424
* The member the constraint was defined on.
2525
*/
26-
private final T property;
26+
private final Property property;
2727

28-
PropertyConstraintLocation(T property) {
28+
PropertyConstraintLocation(Property property) {
2929
this.property = property;
3030
}
3131

@@ -35,7 +35,7 @@ public Class<?> getDeclaringClass() {
3535
}
3636

3737
@Override
38-
public T getConstrainable() {
38+
public Property getConstrainable() {
3939
return property;
4040
}
4141

@@ -72,7 +72,7 @@ public boolean equals(Object o) {
7272
return false;
7373
}
7474

75-
PropertyConstraintLocation<?> that = (PropertyConstraintLocation<?>) o;
75+
PropertyConstraintLocation that = (PropertyConstraintLocation) o;
7676

7777
if ( !property.equals( that.property ) ) {
7878
return false;

0 commit comments

Comments
 (0)