All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mstream.trader.commons.config.schema.SchemaValidator Maven / Gradle / Ivy

The newest version!
package io.mstream.trader.commons.config.schema;


import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.main.JsonSchema;
import io.mstream.trader.commons.config.Config;
import org.slf4j.Logger;

import javax.inject.Inject;
import java.util.function.Predicate;

import static org.slf4j.LoggerFactory.getLogger;


public class SchemaValidator
        implements Predicate {
    
    private static final Logger LOGGER = getLogger(SchemaValidator.class);
    
    private final JsonSchema configSchema;
    
    @Inject
    public SchemaValidator(
            @Config
                    JsonSchema configSchema
    ) {
        
        this.configSchema = configSchema;
    }
    
    @Override
    public boolean test(JsonNode configNode) {
        
        try {
            ProcessingReport report = configSchema.validate(configNode, true);
            return report.isSuccess();
        } catch (ProcessingException e) {
            LOGGER.error("can't parse the config schema", e);
            return false;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy