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

com.relogiclabs.json.schema.exception.JsonSchemaException Maven / Gradle / Ivy

Go to download

The New JSON Schema prioritizes simplicity, conciseness, and readability, making it user-friendly and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements.

There is a newer version: 1.12.1
Show newest version
package com.relogiclabs.json.schema.exception;

import com.relogiclabs.json.schema.message.ActualDetail;
import com.relogiclabs.json.schema.message.ErrorDetail;
import com.relogiclabs.json.schema.message.ExpectedDetail;
import com.relogiclabs.json.schema.tree.Context;
import lombok.Getter;

import static com.relogiclabs.json.schema.internal.util.MiscellaneousHelper.nonNull;

@Getter
public class JsonSchemaException extends CommonException {
    private final ErrorDetail error;
    private final ExpectedDetail expected;
    private final ActualDetail actual;

    public JsonSchemaException(ErrorDetail error, ExpectedDetail expected, ActualDetail actual) {
        this(error, expected, actual, null);
    }

    public JsonSchemaException(ErrorDetail error, ExpectedDetail expected,
                               ActualDetail actual, Throwable cause) {
        super(error.getCode(), format(error, expected, actual), cause);
        this.error = error;
        this.expected = expected;
        this.actual = actual;
    }

    private static String format(ErrorDetail error, ExpectedDetail expected, ActualDetail actual) {
        Context context = nonNull(expected.getContext(), actual.getContext());
        return context.getRuntime().getMessageFormatter().format(error, expected, actual);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy