Improve handling of null fields beneath an array

Previously, if an array contained objects where a field was sometimes
null and sometimes had a value of a consistent type, the type inferred
type was varies. Furthermore, it was not possible for the user to
specify a type other than varies as a mismatch would be detected.

This commit updates JsonFieldTypeResolver so that, when dealing with
an imprecise field path (i.e. a path for a field within an array),
null values that don't match the common type for the field are
ignored. This produces the following behavior when nulls are involved:

- All null fields results in the null type
- A mixture of nulls and a particular type results in the particular
  type
- A mixture of nulls and two or more other types results in the varies
  type

Closes gh-398
This commit is contained in:
Andy Wilkinson
2017-07-01 10:50:01 +01:00
parent 5cef4745f7
commit 6bf1edcd09
2 changed files with 62 additions and 2 deletions

View File

@@ -38,7 +38,7 @@ class JsonFieldTypeResolver {
if (commonType == null) {
commonType = fieldType;
}
else if (fieldType != commonType) {
else if (fieldType != commonType && fieldType != JsonFieldType.NULL) {
return JsonFieldType.VARIES;
}
}