@@ -37,15 +37,15 @@ public class BasicPolymorphicTypeValidator
37
37
* General matcher interface (predicate) for validating class values
38
38
* (base type or resolved subtype)
39
39
*/
40
- protected abstract static class TypeMatcher {
40
+ public abstract static class TypeMatcher { // note: public since 2.11
41
41
public abstract boolean match (Class <?> clazz );
42
42
}
43
43
44
44
/**
45
45
* General matcher interface (predicate) for validating unresolved
46
46
* subclass class name.
47
47
*/
48
- protected abstract static class NameMatcher {
48
+ public abstract static class NameMatcher { // note: public since 2.11
49
49
public abstract boolean match (String clazzName );
50
50
}
51
51
@@ -64,6 +64,11 @@ protected abstract static class NameMatcher {
64
64
* rules are checked.
65
65
*/
66
66
public static class Builder {
67
+ /**
68
+ * Optional set of base types (exact match) that are NOT accepted
69
+ * as base types for polymorphic properties. May be used to prevent "unsafe"
70
+ * base types like {@link java.lang.Object} or {@link java.io.Serializable}.
71
+ */
67
72
protected Set <Class <?>> _invalidBaseTypes ;
68
73
69
74
/**
@@ -151,6 +156,21 @@ public boolean match(Class<?> clazz) {
151
156
});
152
157
}
153
158
159
+ /**
160
+ * Method for appending custom matcher called with base type: if matcher returns
161
+ * {@code true}, all possible subtypes will be accepted; if {@code false}, other
162
+ * matchers are applied.
163
+ *
164
+ * @param matcher Custom matcher to apply to base type
165
+ *
166
+ * @return This Builder to allow call chaining
167
+ *
168
+ * @since 2.11
169
+ */
170
+ public Builder allowIfBaseType (final TypeMatcher matcher ) {
171
+ return _appendBaseMatcher (matcher );
172
+ }
173
+
154
174
/**
155
175
* Method for appending matcher that will mark any polymorphic properties with exact
156
176
* specific class to be invalid.
@@ -238,6 +258,21 @@ public boolean match(String clazzName) {
238
258
});
239
259
}
240
260
261
+ /**
262
+ * Method for appending custom matcher called with resolved subtype: if matcher returns
263
+ * {@code true}, type will be accepted; if {@code false}, other
264
+ * matchers are applied.
265
+ *
266
+ * @param matcher Custom matcher to apply to resolved subtype
267
+ *
268
+ * @return This Builder to allow call chaining
269
+ *
270
+ * @since 2.11
271
+ */
272
+ public Builder allowIfSubType (final TypeMatcher matcher ) {
273
+ return _appendSubClassMatcher (matcher );
274
+ }
275
+
241
276
/**
242
277
* Method for appending matcher that will allow all subtypes that are Java arrays
243
278
* (regardless of element type). Note that this does NOT validate element type
0 commit comments