-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
|
try
|
||||||
{
|
{
|
||||||
var serializer = new JsonSerializer();
|
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)));
|
serializer.Deserialize<Bucket>(new JsonTextReader(new StringReader(json)));
|
||||||
}
|
}
|
||||||
catch (JsonSerializationException ex)
|
catch (JsonSerializationException ex)
|
||||||
|
|||||||
@@ -544,14 +544,23 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore]
|
|
||||||
public void MultipleQuotedIndexes()
|
public void MultipleQuotedIndexes()
|
||||||
{
|
{
|
||||||
JPath path = new JPath("['111119990','3']");
|
JPath path = new JPath("['111119990','3']");
|
||||||
Assert.AreEqual(1, path.Filters.Count);
|
Assert.AreEqual(1, path.Filters.Count);
|
||||||
Assert.AreEqual(2, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes.Count);
|
Assert.AreEqual(2, ((FieldMultipleFilter)path.Filters[0]).Names.Count);
|
||||||
Assert.AreEqual(111119990, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[0]);
|
Assert.AreEqual("111119990", ((FieldMultipleFilter)path.Filters[0]).Names[0]);
|
||||||
Assert.AreEqual(3, ((ArrayMultipleIndexFilter)path.Filters[0]).Indexes[1]);
|
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]
|
[Test]
|
||||||
|
|||||||
@@ -75,4 +75,4 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[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; }
|
public bool CamelCaseText { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether integer values are disallowed.
|
/// Gets or sets a value indicating whether integer values are allowed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if integers are disallowed; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if integers are allowed; otherwise, <c>false</c>.</value>
|
||||||
public bool DisallowIntegerValues { get; set; }
|
public bool AllowIntegerValues { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="StringEnumConverter"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public StringEnumConverter()
|
||||||
|
{
|
||||||
|
AllowIntegerValues = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the JSON representation of the object.
|
/// Writes the JSON representation of the object.
|
||||||
@@ -159,7 +167,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
|
|
||||||
if (reader.TokenType == JsonToken.Integer)
|
if (reader.TokenType == JsonToken.Integer)
|
||||||
{
|
{
|
||||||
if (DisallowIntegerValues)
|
if (!AllowIntegerValues)
|
||||||
throw JsonSerializationException.Create(reader, "Integer value {0} is not allowed.".FormatWith(CultureInfo.InvariantCulture, reader.Value));
|
throw JsonSerializationException.Create(reader, "Integer value {0} is not allowed.".FormatWith(CultureInfo.InvariantCulture, reader.Value));
|
||||||
|
|
||||||
return ConvertUtils.ConvertOrCast(reader.Value, CultureInfo.InvariantCulture, t);
|
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];
|
char currentChar = _expression[_currentIndex];
|
||||||
if (currentChar == '\'')
|
if (currentChar == '\'')
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
return ReadQuotedString();
|
||||||
|
|
||||||
_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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (char.IsDigit(currentChar) || currentChar == '-')
|
else if (char.IsDigit(currentChar) || currentChar == '-')
|
||||||
{
|
{
|
||||||
@@ -559,6 +530,44 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
|||||||
throw new JsonException("Could not read query value.");
|
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)
|
private bool Match(string s)
|
||||||
{
|
{
|
||||||
int currentPosition = _currentIndex;
|
int currentPosition = _currentIndex;
|
||||||
@@ -595,34 +604,50 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
|||||||
throw new JsonException("Could not read query operator.");
|
throw new JsonException("Could not read query operator.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldFilter ParseQuotedField(char indexerCloseChar)
|
private PathFilter ParseQuotedField(char indexerCloseChar)
|
||||||
{
|
{
|
||||||
_currentIndex++;
|
//_currentIndex++;
|
||||||
int start = _currentIndex;
|
//int start = _currentIndex;
|
||||||
|
|
||||||
|
List<string> fields = null;
|
||||||
|
|
||||||
while (_currentIndex < _expression.Length)
|
while (_currentIndex < _expression.Length)
|
||||||
{
|
{
|
||||||
char currentCharacter = _expression[_currentIndex];
|
string field = ReadQuotedString();
|
||||||
if (currentCharacter == '\'')
|
|
||||||
|
//_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++;
|
_currentIndex++;
|
||||||
EnsureLength("Path ended with open indexer.");
|
|
||||||
EatWhitespace();
|
EatWhitespace();
|
||||||
|
|
||||||
if (_expression[_currentIndex] != indexerCloseChar)
|
if (fields == null)
|
||||||
throw new JsonException("Unexpected character while parsing path indexer: " + currentCharacter);
|
fields = new List<string>();
|
||||||
|
|
||||||
string indexer = _expression.Substring(start, length);
|
fields.Add(field);
|
||||||
return new FieldFilter { Name = indexer };
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new JsonException("Unexpected character while parsing path indexer: " + _expression[_currentIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new JsonException("Path ended with open indexer.");
|
throw new JsonException("Path ended with open indexer.");
|
||||||
|
|||||||
@@ -111,6 +111,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
|||||||
@@ -115,6 +115,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
|
|||||||
@@ -121,6 +121,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldMultipleFilter.cs" />
|
||||||
<Compile Include="Linq\JsonPath\JPath.cs" />
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
<Compile Include="Linq\JProperty.cs" />
|
<Compile Include="Linq\JProperty.cs" />
|
||||||
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
||||||
|
|||||||
@@ -91,5 +91,5 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.0.8.16808")]
|
[assembly: AssemblyFileVersion("5.0.8.16815")]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
Reference in New Issue
Block a user