1919import java .lang .reflect .Constructor ;
2020import java .text .MessageFormat ;
2121import java .util .ArrayList ;
22+ import java .util .HashMap ;
2223import java .util .List ;
24+ import java .util .Map ;
2325
2426import com .fasterxml .jackson .databind .JsonNode ;
2527
@@ -62,6 +64,14 @@ public JsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSc
6264 UNION_TYPE ("unionType" , "1030" , new MessageFormat ("{0}: {1} found, but {2} is required" )),
6365 UNIQUE_ITEMS ("uniqueItems" , "1031" , new MessageFormat ("{0}: the items in the array must be unique" ));
6466
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+
6575 private final String value ;
6676 private final String errorCode ;
6777 private final MessageFormat messageFormat ;
@@ -83,6 +93,15 @@ public static List<ValidatorTypeCode> getNonFormatKeywords() {
8393 }
8494 return result ;
8595 }
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+ }
86105
87106 public JsonValidator newValidator (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) throws Exception {
88107 String shortClassName = getValue ();
0 commit comments