Is there a way to limit the size/nested of additionalProperties Map? #171
-
Hello! I'm adding Something like the following maybe: @Size(max = 20)
private Map<String, Object> additionalParameters; I would also want to make sure the values are not nested Maps. Is this something Edit: fixed wording |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
HI @KalCramer, What the configBuilder.forTypesInGeneral()
.withAdditionalPropertiesResolver(scope -> {
if (scope.getType().isInstanceOf(Map.class)) {
// within a Map<Key, Value> allow additionalProperties of the Value type
// if no type parameters are defined, this will result in additionalProperties to be omitted (by way of returning Object.class)
return scope.getTypeParameterFor(Map.class, 1);
}
return null;
}); You'd have to handle the scenario when Regarding your second question: configBuilder.forFields()
.withInstanceAttributeOverride((node, field, context) -> {
Size annotation = field.getAnnotationConsideringFieldAndGetter(Size.class);
if (annotation != null && x.max() < Integer.MAX_VALUE && field.getType().isInstanceOf(Map.class)) {
node.put(context.getKeyword(SchemaKeyword.TAG_PROPERTIES_MAX), x.max());
}
}); |
Beta Was this translation helpful? Give feedback.
HI @KalCramer,
What the
Option.MAP_VALUES_AS_ADDITIONAL_PROPERTIES
does is this:You'd have to handle the scenario when
scope.getTypeParameterFor(Map.class, 1)
returns justObject
, to define an alternati…