File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed
src/main/java/dev/ditsche/validator/error Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public class ErrorBag {
15
15
* Holds information about the errors for each field.
16
16
*/
17
17
@ Getter
18
- HashMap <String , List < String > > errors ;
18
+ HashMap <String , ValidationError > errors ;
19
19
20
20
public ErrorBag () {
21
21
clear ();
@@ -29,9 +29,9 @@ public ErrorBag() {
29
29
* @param message The error message.
30
30
*/
31
31
public void add (String field , String message ) {
32
- List <String > errorList = errors .getOrDefault (field , new LinkedList <>() );
32
+ List <String > errorList = errors .getOrDefault (field , new ValidationError ( field )). getErrors ( );
33
33
errorList .add (message );
34
- errors .put (field , errorList );
34
+ errors .put (field , new ValidationError ( field , errorList ) );
35
35
}
36
36
37
37
/**
Original file line number Diff line number Diff line change
1
+ package dev .ditsche .validator .error ;
2
+
3
+ import lombok .AllArgsConstructor ;
4
+ import lombok .Data ;
5
+ import lombok .NoArgsConstructor ;
6
+
7
+ import java .util .ArrayList ;
8
+ import java .util .LinkedList ;
9
+ import java .util .List ;
10
+
11
+ /**
12
+ * @author Tobias Dittmann
13
+ */
14
+ @ Data
15
+ @ NoArgsConstructor
16
+ @ AllArgsConstructor
17
+ public class ValidationError {
18
+
19
+ private String field ;
20
+
21
+ private List <String > errors ;
22
+
23
+ public ValidationError (String field ) {
24
+ this (field , new LinkedList <>());
25
+ }
26
+
27
+ }
Original file line number Diff line number Diff line change 1
1
package dev .ditsche .validator .error ;
2
2
3
+ import java .util .Collection ;
3
4
import java .util .HashMap ;
5
+ import java .util .HashSet ;
4
6
import java .util .List ;
5
7
6
8
/**
@@ -28,8 +30,8 @@ public ValidationException(ErrorBag errorBag) {
28
30
*
29
31
* @return A mapped representation of fields and its errors.
30
32
*/
31
- public HashMap < String , List < String > > getErrors () {
32
- return errorBag .getErrors ();
33
+ public Collection < ValidationError > getErrors () {
34
+ return errorBag .getErrors (). values () ;
33
35
}
34
36
35
37
}
You can’t perform that action at this time.
0 commit comments