Skip to content

Commit

Permalink
Combine IsValueType check on WriteCoreAsObject
Browse files Browse the repository at this point in the history
  • Loading branch information
jozkee committed Jan 26, 2021
1 parent f980ad0 commit 0eaf149
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ internal sealed override bool WriteCoreAsObject(
JsonSerializerOptions options,
ref WriteStack state)
{
// Value types can never have a null except for Nullable<T>.
if (value == null && IsValueType && Nullable.GetUnderlyingType(TypeToConvert) == null)
if (IsValueType)
{
ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(TypeToConvert);
}
// Value types can never have a null except for Nullable<T>.
if (value == null && Nullable.GetUnderlyingType(TypeToConvert) == null)
{
ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(TypeToConvert);
}

// Root object is a boxed value type.
// Since value types are ignored when detecting cycles
// We need to push it before it gets unboxed.
if (value != null && IsValueType && JsonSerializer.IsIgnoreCyclesEnabled(options))
{
state.ReferenceResolver.PushReferenceForCycleDetection(value);
// Root object is a boxed value type, we need to push it to the reference stack before it gets unboxed here.
if (value != null && JsonSerializer.IsIgnoreCyclesEnabled(options))
{
state.ReferenceResolver.PushReferenceForCycleDetection(value);
}
}

T actualValue = (T)value!;
Expand Down

0 comments on commit 0eaf149

Please sign in to comment.