Skip to content

Access to property schema in custom Format? #1108

Closed Answered by diversit
diversit asked this question in Q&A
Discussion options

You must be logged in to vote

I found a solution by creating a custom class CustomTimePatternFormat, extending TimeFormat, and implementing the Format method

public boolean matches(ExecutionContext executionContext, ValidationContext validationContext, JsonNode node,
                           JsonNode rootNode, JsonNodePath instanceLocation, boolean assertionsEnabled, FormatValidator formatValidator)

and using the formatValidator to get access to other properties of the schema via

formatValidator.getParentSchema().getNode("customTimePattern")

Since the JsonSchema.getNode method is protected, I had to place my custom class in the com.networknt.schema package.

Now my CustomTimePatternFormat class validates the value …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by diversit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant