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

org.everit.json.schema.SchemaException Maven / Gradle / Ivy

Go to download

Implementation of the JSON Schema Core Draft v4 specification built with the org.json API

The newest version!
package org.everit.json.schema;

import java.util.List;

import static java.lang.String.format;
import static java.util.stream.Collectors.joining;

/**
 * Thrown by {@link org.everit.json.schema.loader.SchemaLoader#load()} when it encounters
 * un-parseable schema JSON definition.
 *
 * @author @erosb
 */
public class SchemaException extends RuntimeException {

    private static final long serialVersionUID = 5987489689035036987L;

    private static Object typeOfValue(final Object actualValue) {
        return actualValue == null ? "null" : actualValue.getClass().getSimpleName();
    }

    private static String joinClassNames(final List> expectedTypes) {
        return expectedTypes.stream().map(Class::getSimpleName).collect(joining(", "));
    }

    public SchemaException(final String message) {
        super(message);
    }

    public SchemaException(final String key, final Class expectedType, final Object actualValue) {
        this(format("key %s : expected type: %s , found : %s", key, expectedType
                .getSimpleName(), typeOfValue(actualValue)));
    }

    public SchemaException(final String key, final List> expectedTypes,
            final Object actualValue) {
        this(format("key %s: expected type is one of %s, found: %s",
                key, joinClassNames(expectedTypes), typeOfValue(actualValue)));
    }

    public SchemaException(final String message, final Throwable cause) {
        super(message, cause);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy