internal static Schema ParseJson(JToken j, Names names)
{
if (log.IsDebugEnabled) log.DebugFormat("ParseJson(JToken, Names) - j = {0}, names = {1}", j, names);
if (null == j) throw new ArgumentNullException("j", "j cannot be null.");
if (log.IsDebugEnabled) log.DebugFormat("ParseJson(JToken, Names) - j.GetType() == {0}", j.GetType());
if (j.Type == JTokenType.String)
{
string value = (string)j;
PrimitiveSchema ps = PrimitiveSchema.GetInstance(value);
if (null != ps) return ps;
NamedSchema schema = null;
if (names.TryGetValue(value, out schema)) return schema;
throw new SchemaParseException("Undefined name: " + value);
}
if (j is JArray) return UnionSchema.NewInstance(j as JArray, names);
if (j is JObject)
{
JObject jo = j as JObject;
string type = JsonHelper.GetRequiredString(jo, "type");
Schema schema = PrimitiveSchema.GetInstance(type);
if (null != schema) return schema;
if (type.Equals("array")) return ArraySchema.NewInstance(j, names);
if (type.Equals("map")) return MapSchema.NewInstance(j, names);
schema = NamedSchema.NewInstance(jo, names);
if (null != schema) return schema;
}
throw new AvroTypeException("Invalid JSON for schema: " + j);
}