/// <summary> /// Parse the SearchResults and its search results. /// </summary> /// <param name="reader">The JSON reader.</param> /// <param name="typeToConvert">The type to parse into.</param> /// <param name="options">Serialization options.</param> /// <returns>The deserialized search results.</returns> public override SearchResults <T> Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { Debug.Assert(typeToConvert != null); Debug.Assert(typeToConvert.IsAssignableFrom(typeof(SearchResults <T>))); Debug.Assert(options != null); SearchResults <T> results = new SearchResults <T>(); reader.Expects(JsonTokenType.StartObject); while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) { switch (reader.ExpectsPropertyName()) { case Constants.ODataCountKey: results.TotalCount = reader.ExpectsNullableLong(); break; case Constants.SearchCoverageKey: results.Coverage = reader.ExpectsNullableDouble(); break; case Constants.SearchFacetsKey: ReadFacets(ref reader, results, options); break; case Constants.ODataNextLinkKey: results.NextUri = new Uri(reader.ExpectsString()); break; case Constants.SearchNextPageKey: results.NextOptions = ReadNextPageOptions(ref reader); break; case Constants.ValueKey: reader.Expects(JsonTokenType.StartArray); while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) { SearchResult <T> result = _resultConverter.Read(ref reader, _resultType, options); results.Values.Add(result); } break; default: // Ignore other properties (including OData context, etc.) reader.Skip(); break; } } return(results); }
/// <summary> /// Read the facet result value. /// </summary> /// <param name="reader">JSON reader.</param> /// <param name="options">Serializer options.</param> /// <returns>The facet result.</returns> private static FacetResult ReadFacetResult( ref Utf8JsonReader reader, JsonSerializerOptions options) { FacetResult facet = new FacetResult(); reader.Expects(JsonTokenType.StartObject); while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) { // Get the name of the facet property string facetName = reader.ExpectsPropertyName(); if (facetName == Constants.CountKey) { facet.Count = reader.ExpectsNullableLong(); } else { object value = reader.ReadObject(options); facet[facetName] = value; } } return(facet); }