@SuppressWarnings({"unchecked"})
    private FieldValue optionallyUpgrade(DataType dataType, FieldValue fv) {
        if (fv instanceof StructuredFieldValue) {
            try {
                return structTypes().get(dataType.getName())
                        .getConstructor(StructuredFieldValue.class)
                        .newInstance(fv);
            } catch (java.lang.Exception ex) {
                throw new RuntimeException(ex);
            }
        } else if (fv instanceof Array) {
            Array<FieldValue> array = (Array<FieldValue>) fv;
            DataType nestedType = array.getDataType().getNestedType();
            if (nestedType.getPrimitiveType() == null) {
                array.replaceAll((item) -> optionallyUpgrade(nestedType, item));
            }
        } else if (fv instanceof MapFieldValue) {
            MapFieldValue<FieldValue, FieldValue> map = (MapFieldValue<FieldValue, FieldValue>) fv;
            DataType valueTypeType = map.getDataType().getValueType();
            if (valueTypeType.getPrimitiveType() == null) {
                map.replaceAll((key, value) -> optionallyUpgrade(valueTypeType, value));
            }
        }
        return fv;
    }
If the FieldValue is a StructuredFieldValue it will upgrade to the concrete type
@param field to upgrade
@param fv value to upgrade
@return fv or upgraded fv
docproc/src/main/java/com/yahoo/docproc/AbstractConcreteDocumentFactory.java