public override MetadataDictionary? Read()

in src/Elastic.CommonSchema/Serialization/MetadataDictionaryConverter.cs [24:54]


		public override MetadataDictionary? Read(ref Utf8JsonReader reader, Type? typeToConvert, JsonSerializerOptions options)
		{
			if (reader.TokenType != JsonTokenType.StartObject)
				throw new JsonException($"JsonTokenType was of type {reader.TokenType}, only objects are supported");

			var dictionary = new MetadataDictionary();
			var originalDepth = reader.CurrentDepth;
			while (reader.Read())
			{
				if (reader.TokenType == JsonTokenType.EndObject)
				{
					if (reader.CurrentDepth <= originalDepth)
						break;
					continue;
				}

				if (reader.TokenType != JsonTokenType.PropertyName)
					throw new JsonException("JsonTokenType was not PropertyName");

				var propertyName = reader.GetString();

				if (propertyName.IsNullOrEmpty())
					throw new JsonException("Failed to get property name");

				reader.Read();
				var value = ExtractValue(ref reader, options);
				dictionary.Add(propertyName, value);
			}

			return dictionary.Count > 0 ? dictionary : null;
		}