CreateCollection(ref reader, ref state, options);
+ state.Current.JsonPropertyInfo = elementTypeInfo.PropertyInfoForTypeInfo;
JsonConverter<TElement> elementConverter = GetElementConverter(elementTypeInfo);
if (elementConverter.CanUseDirectReadOrWrite && state.Current.NumberHandling == null)
{
{
ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(TypeToConvert);
}
+
+ state.Current.JsonPropertyInfo = elementTypeInfo.PropertyInfoForTypeInfo;
}
// Handle the metadata properties.
if (state.Current.ObjectState < StackFrameObjectState.CreatedObject)
{
CreateCollection(ref reader, ref state, options);
- state.Current.JsonPropertyInfo = state.Current.JsonTypeInfo.ElementTypeInfo!.PropertyInfoForTypeInfo;
state.Current.ObjectState = StackFrameObjectState.CreatedObject;
}
CreateCollection(ref reader, ref state);
+ state.Current.JsonPropertyInfo = elementTypeInfo.PropertyInfoForTypeInfo;
_valueConverter ??= GetConverter<TValue>(elementTypeInfo);
if (_valueConverter.CanUseDirectReadOrWrite && state.Current.NumberHandling == null)
{
}
state.Current.ObjectState = StackFrameObjectState.StartToken;
+ state.Current.JsonPropertyInfo = elementTypeInfo.PropertyInfoForTypeInfo;
}
// Handle the metadata properties.
}
else
{
- JsonTypeInfo jsonTypeInfo;
+ JsonTypeInfo jsonTypeInfo = Current.JsonPropertyInfo?.JsonTypeInfo ?? Current.CtorArgumentState!.JsonParameterInfo!.JsonTypeInfo;
JsonNumberHandling? numberHandling = Current.NumberHandling;
ConverterStrategy converterStrategy = Current.JsonTypeInfo.PropertyInfoForTypeInfo.ConverterStrategy;
- if (converterStrategy == ConverterStrategy.Object)
- {
- if (Current.JsonPropertyInfo != null)
- {
- jsonTypeInfo = Current.JsonPropertyInfo.JsonTypeInfo;
- }
- else
- {
- jsonTypeInfo = Current.CtorArgumentState!.JsonParameterInfo!.JsonTypeInfo;
- }
- }
- else if (converterStrategy == ConverterStrategy.Value)
- {
- // Although ConverterStrategy.Value doesn't push, a custom custom converter may re-enter serialization.
- jsonTypeInfo = Current.JsonPropertyInfo!.JsonTypeInfo;
- }
- else
- {
- Debug.Assert(((ConverterStrategy.Enumerable | ConverterStrategy.Dictionary) & converterStrategy) != 0);
- jsonTypeInfo = Current.JsonTypeInfo.ElementTypeInfo!;
- }
-
EnsurePushCapacity();
_stack[_count - 1] = Current;
Current = default;
if (string.IsNullOrEmpty(message))
{
// Use a default message.
- Type? propertyType = state.Current.JsonPropertyInfo?.PropertyType;
- if (propertyType == null)
- {
- propertyType = state.Current.JsonTypeInfo?.Type;
- }
-
+ Type propertyType = state.Current.JsonTypeInfo.Type;
message = SR.Format(SR.DeserializeUnableToConvertValue, propertyType);
ex.AppendPathInformation = true;
}
Debug.Assert(!message.Contains(" Path: "));
// Obtain the type to show in the message.
- Type? propertyType = state.Current.JsonPropertyInfo?.PropertyType;
- if (propertyType == null)
- {
- propertyType = state.Current.JsonTypeInfo.Type;
- }
+ Type propertyType = state.Current.JsonTypeInfo.Type;
if (!message.Contains(propertyType.ToString()))
{
Debug.Assert(!message.Contains(" Path: "));
// Obtain the type to show in the message.
- Type? propertyType = state.Current.JsonPropertyInfo?.PropertyType;
- if (propertyType == null)
- {
- propertyType = state.Current.JsonTypeInfo.Type;
- }
+ Type propertyType = state.Current.JsonTypeInfo.Type;
if (!message.Contains(propertyType.ToString()))
{
ex = Assert.Throws<NotSupportedException>(() => JsonSerializer.Deserialize<TopLevelPocoWithNoConverter>(Json, options));
Assert.Contains(typeof(int[,]).ToString(), ex.ToString());
- Assert.Contains(typeof(ChildPocoWithNoConverterAndInvalidProperty).ToString(), ex.ToString());
+ Assert.Contains(typeof(ChildPocoWithNoConverter).ToString(), ex.ToString());
Assert.Contains("Path: $.InvalidProperty | LineNumber: 0 | BytePositionInLine: 20.", ex.ToString());
Assert.Equal(2, ex.ToString().Split(new string[] { "Path:" }, StringSplitOptions.None).Length);
ex = Assert.Throws<NotSupportedException>(() => JsonSerializer.Serialize(poco, options));
Assert.Contains(typeof(int[,]).ToString(), ex.ToString());
- Assert.Contains(typeof(ChildPocoWithNoConverterAndInvalidProperty).ToString(), ex.ToString());
+ Assert.Contains(typeof(ChildPocoWithNoConverter).ToString(), ex.ToString());
Assert.Contains("Path: $.InvalidProperty.", ex.ToString());
Assert.Equal(2, ex.ToString().Split(new string[] { "Path:" }, StringSplitOptions.None).Length);
}
JsonSerializer.Serialize(new ClassWithPropertyToClassWithInvalidArray()));
Assert.Contains(typeof(int[,]).ToString(), ex.Message);
- Assert.Contains(typeof(ClassWithInvalidArray).ToString(), ex.Message);
+ Assert.Contains(typeof(ClassWithPropertyToClassWithInvalidArray).ToString(), ex.Message);
Assert.Contains("Path: $.Inner.", ex.Message);
// The original exception contains the type.