-Fix builds
-Added support for multiple fields in a query indexer -Renamed DisallowIntegerValues to AllowIntegerValues
This commit is contained in:
@@ -376,7 +376,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
try
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
serializer.Converters.Add(new StringEnumConverter { DisallowIntegerValues = true });
|
||||
serializer.Converters.Add(new StringEnumConverter { AllowIntegerValues = false });
|
||||
serializer.Deserialize<Bucket>(new JsonTextReader(new StringReader(json)));
|
||||
}
|
||||
catch (JsonSerializationException ex)
|
||||
|
||||
@@ -544,14 +544,23 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void MultipleQuotedIndexes()
|
||||
{
|
||||
JPath path = new JPath("['111119990','3']");
|
||||
Assert.AreEqual(1, path.Filters.Count);
|
||||
Assert.AreEqual(2, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes.Count);
|
||||
Assert.AreEqual(111119990, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[0]);
|
||||
Assert.AreEqual(3, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[1]);
|
||||
Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count);
|
||||
Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]);
|
||||
Assert.AreEqual("3", ((FieldMultipleFilter)path.Filters[0]).Names[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultipleQuotedIndexesWithWhitespace()
|
||||
{
|
||||
JPath path = new JPath("[ '111119990' , '3' ]");
|
||||
Assert.AreEqual(1, path.Filters.Count);
|
||||
Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count);
|
||||
Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]);
|
||||
Assert.AreEqual("3", ((FieldMultipleFilter)path.Filters[0]).Names[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -75,4 +75,4 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.8.16808")]
|
||||
[assembly: AssemblyFileVersion("5.0.8.16815")]
|
||||
|
||||
@@ -52,10 +52,18 @@ namespace Newtonsoft.Json.Converters
|
||||
public bool CamelCaseText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether integer values are disallowed.
|
||||
/// Gets or sets a value indicating whether integer values are allowed.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if integers are disallowed; otherwise, <c>false</c>.</value>
|
||||
public bool DisallowIntegerValues { get; set; }
|
||||
/// <value><c>true</c> if integers are allowed; otherwise, <c>false</c>.</value>
|
||||
public bool AllowIntegerValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StringEnumConverter"/> class.
|
||||
/// </summary>
|
||||
public StringEnumConverter()
|
||||
{
|
||||
AllowIntegerValues = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
@@ -159,7 +167,7 @@ namespace Newtonsoft.Json.Converters
|
||||
|
||||
if (reader.TokenType == JsonToken.Integer)
|
||||
{
|
||||
if (DisallowIntegerValues)
|
||||
if (!AllowIntegerValues)
|
||||
throw JsonSerializationException.Create(reader, "Integer value {0} is not allowed.".FormatWith(CultureInfo.InvariantCulture, reader.Value));
|
||||
|
||||
return ConvertUtils.ConvertOrCast(reader.Value, CultureInfo.InvariantCulture, t);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
internal class FieldMultipleFilter : PathFilter
|
||||
{
|
||||
public List<string> Names { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
JObject o = t as JObject;
|
||||
if (o != null)
|
||||
{
|
||||
foreach (string name in Names)
|
||||
{
|
||||
JToken v = o[name];
|
||||
|
||||
if (v != null)
|
||||
yield return v;
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// if (errorWhenNoMatch)
|
||||
// throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,36 +472,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
char currentChar = _expression[_currentIndex];
|
||||
if (currentChar == '\'')
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
_currentIndex++;
|
||||
while (_currentIndex < _expression.Length)
|
||||
{
|
||||
currentChar = _expression[_currentIndex];
|
||||
if (currentChar == '\\' && _currentIndex + 1 < _expression.Length)
|
||||
{
|
||||
_currentIndex++;
|
||||
|
||||
if (_expression[_currentIndex] == '\'')
|
||||
sb.Append('\'');
|
||||
else if (_expression[_currentIndex] == '\\')
|
||||
sb.Append('\\');
|
||||
else
|
||||
throw new JsonException(@"Unknown escape chracter: \" + _expression[_currentIndex]);
|
||||
|
||||
_currentIndex++;
|
||||
}
|
||||
else if (currentChar == '\'')
|
||||
{
|
||||
_currentIndex++;
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentIndex++;
|
||||
sb.Append(currentChar);
|
||||
}
|
||||
}
|
||||
return ReadQuotedString();
|
||||
}
|
||||
else if (char.IsDigit(currentChar) || currentChar == '-')
|
||||
{
|
||||
@@ -559,6 +530,44 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
throw new JsonException("Could not read query value.");
|
||||
}
|
||||
|
||||
private string ReadQuotedString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
_currentIndex++;
|
||||
while (_currentIndex < _expression.Length)
|
||||
{
|
||||
char currentChar = _expression[_currentIndex];
|
||||
if (currentChar == '\\' && _currentIndex + 1 < _expression.Length)
|
||||
{
|
||||
_currentIndex++;
|
||||
|
||||
if (_expression[_currentIndex] == '\'')
|
||||
sb.Append('\'');
|
||||
else if (_expression[_currentIndex] == '\\')
|
||||
sb.Append('\\');
|
||||
else
|
||||
throw new JsonException(@"Unknown escape chracter: \" + _expression[_currentIndex]);
|
||||
|
||||
_currentIndex++;
|
||||
}
|
||||
else if (currentChar == '\'')
|
||||
{
|
||||
_currentIndex++;
|
||||
{
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentIndex++;
|
||||
sb.Append(currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonException("Path ended with an open string.");
|
||||
}
|
||||
|
||||
private bool Match(string s)
|
||||
{
|
||||
int currentPosition = _currentIndex;
|
||||
@@ -595,34 +604,50 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
throw new JsonException("Could not read query operator.");
|
||||
}
|
||||
|
||||
private FieldFilter ParseQuotedField(char indexerCloseChar)
|
||||
private PathFilter ParseQuotedField(char indexerCloseChar)
|
||||
{
|
||||
_currentIndex++;
|
||||
int start = _currentIndex;
|
||||
//_currentIndex++;
|
||||
//int start = _currentIndex;
|
||||
|
||||
List<string> fields = null;
|
||||
|
||||
while (_currentIndex < _expression.Length)
|
||||
{
|
||||
char currentCharacter = _expression[_currentIndex];
|
||||
if (currentCharacter == '\'')
|
||||
string field = ReadQuotedString();
|
||||
|
||||
//_currentIndex++;
|
||||
//EnsureLength("Path ended with open indexer.");
|
||||
EatWhitespace();
|
||||
EnsureLength("Path ended with open indexer.");
|
||||
|
||||
if (_expression[_currentIndex] == indexerCloseChar)
|
||||
{
|
||||
_currentIndex++;
|
||||
|
||||
if (fields != null)
|
||||
{
|
||||
fields.Add(field);
|
||||
return new FieldMultipleFilter { Names = fields };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FieldFilter { Name = field };
|
||||
}
|
||||
}
|
||||
else if (_expression[_currentIndex] == ',')
|
||||
{
|
||||
int length = _currentIndex - start;
|
||||
|
||||
if (length == 0)
|
||||
throw new JsonException("Empty path indexer.");
|
||||
|
||||
// check that character after the quote is to close the index
|
||||
_currentIndex++;
|
||||
EnsureLength("Path ended with open indexer.");
|
||||
EatWhitespace();
|
||||
|
||||
if (_expression[_currentIndex] != indexerCloseChar)
|
||||
throw new JsonException("Unexpected character while parsing path indexer: " + currentCharacter);
|
||||
if (fields == null)
|
||||
fields = new List<string>();
|
||||
|
||||
string indexer = _expression.Substring(start, length);
|
||||
return new FieldFilter { Name = indexer };
|
||||
fields.Add(field);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonException("Unexpected character while parsing path indexer: " + _expression[_currentIndex]);
|
||||
}
|
||||
|
||||
_currentIndex++;
|
||||
}
|
||||
|
||||
throw new JsonException("Path ended with open indexer.");
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
|
||||
@@ -123,6 +123,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
|
||||
@@ -187,6 +187,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||
<Compile Include="Linq\JProperty.cs" />
|
||||
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
||||
|
||||
@@ -91,5 +91,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.8.16808")]
|
||||
[assembly: AssemblyFileVersion("5.0.8.16815")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
Reference in New Issue
Block a user