io.vertx.ext.web.validation.impl.parser.ObjectParser Maven / Gradle / Ivy
The newest version!
package io.vertx.ext.web.validation.impl.parser;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;
import java.util.regex.Pattern;
public abstract class ObjectParser {
private Map> propertiesParsers;
private Map> patternPropertiesParsers;
protected ValueParser additionalPropertiesParser;
public ObjectParser(Map> propertiesParsers, Map> patternPropertiesParsers, ValueParser additionalPropertiesParser) {
this.propertiesParsers = propertiesParsers;
this.patternPropertiesParsers = patternPropertiesParsers;
this.additionalPropertiesParser = additionalPropertiesParser;
}
protected Map.Entry parseField(String key, X serialized) {
ValueParser valueParser = null;
if (propertiesParsers != null && propertiesParsers.containsKey(key))
valueParser = propertiesParsers.get(key);
else if (patternPropertiesParsers != null) {
valueParser = patternPropertiesParsers
.entrySet()
.stream()
.filter(e -> e.getKey().matcher(key).find())
.map(Map.Entry::getValue)
.findFirst()
.orElse(null);
}
if (valueParser == null) {
valueParser = getAdditionalPropertiesParserIfRequired();
}
if (valueParser == null) return null;
if (mustNullateValue(serialized, valueParser)) return new SimpleImmutableEntry<>(key, null);
return new SimpleImmutableEntry<>(key, valueParser.parse(serialized));
}
protected abstract ValueParser getAdditionalPropertiesParserIfRequired();
protected abstract boolean mustNullateValue(X serialized, ValueParser parser);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy