clesaec commented on code in PR #1919:
URL: https://github.com/apache/avro/pull/1919#discussion_r1000403327
##########
lang/java/avro/src/main/java/org/apache/avro/Schema.java:
##########
@@ -1619,6 +1619,16 @@ private static JsonNode validateDefault(String
fieldName, Schema schema, JsonNod
return defaultValue;
}
+ /**
+ * Checks if a JSON value matches the schema.
+ *
+ * @param jsonValue a value to check against the schema
+ * @return true if the value is valid according to this schema
+ */
+ public boolean isValidValue(JsonNode jsonValue) {
+ return isValidDefault(this, jsonValue);
+ }
Review Comment:
:+1: use standard method instead of static (_it may replace private static
boolean isValidDefault in near future_), and avoid this long switch/case on
schema/type.
About default value on union type, I wonder if it couldn't be even better to
change logic and get the first compatible Schema of union with the value (And
throw exception if none) ?
I did this code in local (_and partially copy yours_), and it seems to work
fine (at least for unit test). I will put more details in linked JIRA Ticket in
few minutes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]