-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.networknt.schema; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
public class ConstValidator extends BaseJsonValidator implements JsonValidator { | ||
private static final Logger logger = LoggerFactory.getLogger(ConstValidator.class); | ||
JsonNode schemaNode; | ||
|
||
public ConstValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) { | ||
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.CONST, validationContext); | ||
this.schemaNode = schemaNode; | ||
} | ||
|
||
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) { | ||
debug(logger, node, rootNode, at); | ||
|
||
Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>(); | ||
if(schemaNode.isNumber() && node.isNumber()) { | ||
if(schemaNode.decimalValue().compareTo(node.decimalValue()) != 0) { | ||
errors.add(buildValidationMessage(at, schemaNode.asText())); | ||
} | ||
} else if (!schemaNode.equals(node)) { | ||
errors.add(buildValidationMessage(at, schemaNode.asText())); | ||
} | ||
return Collections.unmodifiableSet(errors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters