Avro.JsonHelper.GetRequiredString C# (CSharp) Method

GetRequiredString() public static method

public static GetRequiredString ( JToken j, string property ) : string
j JToken
property string
return string
        public static string GetRequiredString(JToken j, string property)
        {
            string value = GetOptionalString(j, property);
            if (string.IsNullOrEmpty(value)) throw new SchemaParseException(string.Format("No \"{0}\" JSON field: {1}", property, j));
            return value;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Creates a new field for the record
        /// </summary>
        /// <param name="jfield">JSON object for the field</param>
        /// <param name="pos">position number of the field</param>
        /// <param name="names">list of named schemas already read</param>
        /// <param name="encspace">enclosing namespace of the records schema</param>
        /// <returns>new Field object</returns>
        private static Field createField(JToken jfield, int pos, SchemaNames names, string encspace)
        {
            var name = JsonHelper.GetRequiredString(jfield, "name");
            var doc  = JsonHelper.GetOptionalString(jfield, "doc");

            var jorder = JsonHelper.GetOptionalString(jfield, "order");

            Field.SortOrder sortorder = Field.SortOrder.ignore;
            if (null != jorder)
            {
                sortorder = (Field.SortOrder)Enum.Parse(typeof(Field.SortOrder), jorder);
            }

            var aliases      = Field.GetAliases(jfield);
            var props        = Schema.GetProperties(jfield);
            var defaultValue = jfield["default"];

            JToken jtype = jfield["type"];

            if (null == jtype)
            {
                throw new SchemaParseException($"'type' was not found for field: name at '{jfield.Path}'");
            }
            var schema = Schema.ParseJson(jtype, names, encspace);

            return(new Field(schema, name, aliases, pos, doc, defaultValue, sortorder, props));
        }
All Usage Examples Of Avro.JsonHelper::GetRequiredString