|
|
@@ -1,9 +1,12 @@
|
|
|
package org.leumasjaffe.json.schema;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import org.leumasjaffe.container.Either;
|
|
|
+
|
|
|
import lombok.AccessLevel;
|
|
|
import lombok.Getter;
|
|
|
import lombok.experimental.FieldDefaults;
|
|
|
@@ -11,24 +14,38 @@ import lombok.experimental.FieldDefaults;
|
|
|
@SuppressWarnings("serial")
|
|
|
@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class ValidationException extends IllegalArgumentException {
|
|
|
+ List<Either<String, Integer>> jsonPath = new ArrayList<>();
|
|
|
@Getter List<ValidationException> causingExceptions;
|
|
|
-
|
|
|
- public ValidationException() {
|
|
|
- this.causingExceptions = Collections.emptyList();
|
|
|
+
|
|
|
+ private ValidationException(Either<String, Integer> path, String message,
|
|
|
+ ValidationException... causes) {
|
|
|
+ super(message);
|
|
|
+ this.jsonPath.add(path);
|
|
|
+ this.causingExceptions = Collections.unmodifiableList(Arrays.asList(causes));
|
|
|
}
|
|
|
|
|
|
- public ValidationException(String s) {
|
|
|
- super(s);
|
|
|
- this.causingExceptions = Collections.emptyList();
|
|
|
+ public ValidationException(String key, String message) {
|
|
|
+ this(Either.ofLeft(key), message);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ValidationException(int index, String message) {
|
|
|
+ this(Either.ofRight(index), message);
|
|
|
}
|
|
|
|
|
|
- public ValidationException(ValidationException... causes) {
|
|
|
- this.causingExceptions = Collections.unmodifiableList(Arrays.asList(causes));
|
|
|
+ public ValidationException(String key, String message,
|
|
|
+ ValidationException... causes) {
|
|
|
+ this(Either.ofLeft(key), message, causes);
|
|
|
}
|
|
|
|
|
|
- public ValidationException(String message, ValidationException... causes) {
|
|
|
- super(message);
|
|
|
- this.causingExceptions = Collections.unmodifiableList(Arrays.asList(causes));
|
|
|
+ public ValidationException(int index, String message,
|
|
|
+ ValidationException... causes) {
|
|
|
+ this(Either.ofRight(index), message, causes);
|
|
|
}
|
|
|
|
|
|
+ public String getPath() {
|
|
|
+ final StringBuilder path = new StringBuilder("#");
|
|
|
+ jsonPath.forEach(e -> path.append('/').append(e));
|
|
|
+ return path.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|