@@ -208,19 +208,21 @@ private Map<String, JsonValidator> read(JsonNode schemaNode) {
208
208
Map <String , JsonValidator > validators = new HashMap <String , JsonValidator >();
209
209
if (schemaNode .isBoolean ()) {
210
210
if (schemaNode .booleanValue ()) {
211
- JsonValidator validator = validationContext .newValidator (getSchemaPath (), "true" , schemaNode , this );
211
+ final String customMessage = getCustomMessage (schemaNode , "true" );
212
+ JsonValidator validator = validationContext .newValidator (getSchemaPath (), "true" , schemaNode , this , customMessage );
212
213
validators .put (getSchemaPath () + "/true" , validator );
213
214
} else {
214
- JsonValidator validator = validationContext .newValidator (getSchemaPath (), "false" , schemaNode , this );
215
+ final String customMessage = getCustomMessage (schemaNode , "false" );
216
+ JsonValidator validator = validationContext .newValidator (getSchemaPath (), "false" , schemaNode , this , customMessage );
215
217
validators .put (getSchemaPath () + "/false" , validator );
216
218
}
217
219
} else {
218
220
Iterator <String > pnames = schemaNode .fieldNames ();
219
221
while (pnames .hasNext ()) {
220
222
String pname = pnames .next ();
221
223
JsonNode nodeToUse = pname .equals ("if" ) ? schemaNode : schemaNode .get (pname );
222
-
223
- JsonValidator validator = validationContext .newValidator (getSchemaPath (), pname , nodeToUse , this );
224
+ String customMessage = getCustomMessage ( schemaNode , pname );
225
+ JsonValidator validator = validationContext .newValidator (getSchemaPath (), pname , nodeToUse , this , customMessage );
224
226
if (validator != null ) {
225
227
validators .put (getSchemaPath () + "/" + pname , validator );
226
228
@@ -234,6 +236,24 @@ private Map<String, JsonValidator> read(JsonNode schemaNode) {
234
236
return validators ;
235
237
}
236
238
239
+ private String getCustomMessage (JsonNode schemaNode , String pname ) {
240
+ final JsonSchema parentSchema = getParentSchema ();
241
+ final JsonNode message = getMessageNode (schemaNode , parentSchema );
242
+ if (message != null && message .get (pname ) != null ) {
243
+ return message .get (pname ).asText ();
244
+ }
245
+ return null ;
246
+ }
247
+
248
+ private JsonNode getMessageNode (JsonNode schemaNode , JsonSchema parentSchema ) {
249
+ JsonNode nodeContainingMessage ;
250
+ if (parentSchema == null )
251
+ nodeContainingMessage = schemaNode ;
252
+ else
253
+ nodeContainingMessage = parentSchema .schemaNode ;
254
+ return nodeContainingMessage .get ("message" );
255
+ }
256
+
237
257
/************************ START OF VALIDATE METHODS **********************************/
238
258
239
259
public Set <ValidationMessage > validate (JsonNode jsonNode , JsonNode rootNode , String at ) {
0 commit comments