-Added support for Serializable attribute and MemberSerialization.Fields

-Added support for ignoring properties with NonSerializable attribute
-Added MaxDepth to JsonReader/JsonSerializer/JsonSerializerSettings
This commit is contained in:
James Newton-King
2012-04-08 19:33:09 +12:00
parent 83618b1ea0
commit e3cec969ef
20 changed files with 620 additions and 118 deletions
+22 -20
View File
@@ -109,6 +109,7 @@ namespace Newtonsoft.Json
private JsonPosition _currentPosition;
private CultureInfo _culture;
private DateTimeZoneHandling _dateTimeZoneHandling;
private int? _maxDepth;
/// <summary>
/// Gets the current reader state.
@@ -149,6 +150,18 @@ namespace Newtonsoft.Json
set { _dateTimeZoneHandling = value; }
}
public int? MaxDepth
{
get { return _maxDepth; }
set
{
if (value <= 0)
throw new ArgumentException("Value must be positive.", "value");
_maxDepth = value;
}
}
/// <summary>
/// Gets the type of the current JSON token.
/// </summary>
@@ -235,11 +248,15 @@ namespace Newtonsoft.Json
else
{
_stack.Add(_currentPosition);
var state = new JsonPosition
JsonPosition state = new JsonPosition
{
Type = value
};
_currentPosition = state;
// this is a little hacky because Depth increases when first property/value is written but only testing here is faster/simpler
if (_maxDepth != null && Depth + 1 > _maxDepth)
throw new JsonReaderException("This reader's MaxDepth of {0} has been exceeded.".FormatWith(CultureInfo.InvariantCulture, _maxDepth));
}
}
@@ -667,7 +684,10 @@ namespace Newtonsoft.Json
/// <param name="value">The value.</param>
protected void SetToken(JsonToken newToken, object value)
{
JsonToken previousToken = _tokenType;
_tokenType = newToken;
_value = value;
switch (newToken)
{
@@ -711,8 +731,6 @@ namespace Newtonsoft.Json
UpdateScopeWithFinishedValue();
break;
}
_value = value;
}
private void UpdateScopeWithFinishedValue()
@@ -789,24 +807,8 @@ namespace Newtonsoft.Json
case JsonToken.StartArray:
case JsonToken.StartConstructor:
return true;
case JsonToken.PropertyName:
case JsonToken.None:
case JsonToken.Comment:
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.String:
case JsonToken.Boolean:
case JsonToken.Null:
case JsonToken.Undefined:
case JsonToken.EndObject:
case JsonToken.EndArray:
case JsonToken.EndConstructor:
case JsonToken.Date:
case JsonToken.Raw:
case JsonToken.Bytes:
return false;
default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("token", token, "Unexpected JsonToken value.");
return false;
}
}