On 08/16/2010 01:08 PM, John Kristian wrote:
It seems like it would better for schema parsing (or perhaps resolution) to fail if the default value doesn't match the first type in the union. That would require people to clarify existing schemas. Would it cause trouble in other ways?
Defaults can be ambiguous. For example, {"a":1} as the default value for a union of a record with a field named "a" of type int and a map with long values, or "foo" for the default value of a union of string, bytes and an enum. If you switched the order in the union, you'd get no warning.
However we could do a better job of detecting some erroneous default values earlier. The resolver currently handles default values in ResolvingGrammarGenerator#encode(). We could add more checks there. For example, the NULL case there could throw an exception if the JSON node n is non-null. Similarly, the INT case should throw an exception if JSON node is non-numeric (currently it calls n.getIntValue() which, unfortunately returns zero for non-numeric nodes).
Would you like to file an issue in Jira for this? If you can, please provide a patch & unit tests.
Thanks, Doug
