-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search SDK: Bug fixes and JSON blob parsing support (#3012)
* Search SDK: Fix bug that prevented infinite double values from deserializing Also added a bunch of test coverage around boundary values. * Search SDK: Adding convenience method for enabling JSON blob indexers * Search SDK: Bumping version to 3.0.3 and changing release notes * Updating Analyze API tests to include MS language tokenizers * Forgot about one case * Search SDK: Adding missing descriptions The Name properties of Tokenizer, TokenFilter, and CharFilter didn't have descriptions in the Swagger spec. Now that we've added them, the corresponding generated C# properties now have comments.
- Loading branch information
1 parent
07cc2b3
commit c4ffe84
Showing
18 changed files
with
2,626 additions
and
1,154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Search/Microsoft.Azure.Search/Customizations/Serialization/Private/DoubleConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for | ||
// license information. | ||
|
||
namespace Microsoft.Azure.Search.Serialization | ||
{ | ||
using System; | ||
using System.Globalization; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Serializes doubles to and from the OData wire format. | ||
/// </summary> | ||
internal class DoubleConverter : JsonConverter | ||
{ | ||
private const string ODataNegativeInfinity = "-INF"; | ||
private const string ODataPositiveInfinity = "INF"; | ||
|
||
public override bool CanConvert(Type objectType) => | ||
typeof(double?).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()) || | ||
typeof(double).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.TokenType == JsonToken.Null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (reader.TokenType == JsonToken.String) | ||
{ | ||
string strValue = (string)reader.Value; | ||
|
||
switch (strValue) | ||
{ | ||
case ODataPositiveInfinity: return Double.PositiveInfinity; | ||
case ODataNegativeInfinity: return Double.NegativeInfinity; | ||
default: return Double.Parse(strValue, CultureInfo.InvariantCulture); | ||
} | ||
} | ||
|
||
// We can't use a direct cast because sometimes we get integers from the reader. | ||
return Convert.ToDouble(reader.Value); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value == null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
double doubleValue = (double)value; | ||
|
||
if (Double.IsNegativeInfinity(doubleValue)) | ||
{ | ||
writer.WriteValue(ODataNegativeInfinity); | ||
} | ||
else if (Double.IsPositiveInfinity(doubleValue)) | ||
{ | ||
writer.WriteValue(ODataPositiveInfinity); | ||
} | ||
else | ||
{ | ||
writer.WriteValue(doubleValue); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.