19
19
import java .lang .reflect .Constructor ;
20
20
import java .text .MessageFormat ;
21
21
import java .util .ArrayList ;
22
+ import java .util .HashMap ;
22
23
import java .util .List ;
24
+ import java .util .Map ;
23
25
24
26
import com .fasterxml .jackson .databind .JsonNode ;
25
27
@@ -62,6 +64,14 @@ public JsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSc
62
64
UNION_TYPE ("unionType" , "1030" , new MessageFormat ("{0}: {1} found, but {2} is required" )),
63
65
UNIQUE_ITEMS ("uniqueItems" , "1031" , new MessageFormat ("{0}: the items in the array must be unique" ));
64
66
67
+ private static Map <String , ValidatorTypeCode > constants = new HashMap <String , ValidatorTypeCode >();
68
+
69
+ static {
70
+ for (ValidatorTypeCode c : values ()) {
71
+ constants .put (c .value , c );
72
+ }
73
+ }
74
+
65
75
private final String value ;
66
76
private final String errorCode ;
67
77
private final MessageFormat messageFormat ;
@@ -83,6 +93,15 @@ public static List<ValidatorTypeCode> getNonFormatKeywords() {
83
93
}
84
94
return result ;
85
95
}
96
+
97
+ public static ValidatorTypeCode fromValue (String value ) {
98
+ ValidatorTypeCode constant = constants .get (value );
99
+ if (constant == null ) {
100
+ throw new IllegalArgumentException (value );
101
+ } else {
102
+ return constant ;
103
+ }
104
+ }
86
105
87
106
public JsonValidator newValidator (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) throws Exception {
88
107
String shortClassName = getValue ();
0 commit comments