-Fixed reading some types from KeyValuePairConverter incorrectly

This commit is contained in:
James Newton-King
2017-05-28 00:47:09 +12:00
parent 2b647efc7b
commit 7726b51091
4 changed files with 131 additions and 58 deletions
+56
View File
@@ -1164,6 +1164,62 @@ namespace Newtonsoft.Json
}
}
internal void ReadForTypeAndAssert(JsonContract contract, bool hasConverter)
{
if (!ReadForType(contract, hasConverter))
{
throw JsonSerializationException.Create(this, "Unexpected end when reading JSON.");
}
}
internal bool ReadForType(JsonContract contract, bool hasConverter)
{
// don't read properties with converters as a specific value
// the value might be a string which will then get converted which will error if read as date for example
if (hasConverter)
{
return Read();
}
ReadType t = (contract != null) ? contract.InternalReadType : ReadType.Read;
switch (t)
{
case ReadType.Read:
return ReadAndMoveToContent();
case ReadType.ReadAsInt32:
ReadAsInt32();
break;
case ReadType.ReadAsDecimal:
ReadAsDecimal();
break;
case ReadType.ReadAsDouble:
ReadAsDouble();
break;
case ReadType.ReadAsBytes:
ReadAsBytes();
break;
case ReadType.ReadAsBoolean:
ReadAsBoolean();
break;
case ReadType.ReadAsString:
ReadAsString();
break;
case ReadType.ReadAsDateTime:
ReadAsDateTime();
break;
#if HAVE_DATE_TIME_OFFSET
case ReadType.ReadAsDateTimeOffset:
ReadAsDateTimeOffset();
break;
#endif
default:
throw new ArgumentOutOfRangeException();
}
return (TokenType != JsonToken.None);
}
internal bool ReadAndMoveToContent()
{
return Read() && MoveToContent();