-Fixed reading some types from KeyValuePairConverter incorrectly
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user