Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate fails to overwrite JToken value with mismatched type #2512

Closed
ejball opened this issue Apr 14, 2021 · 1 comment
Closed

Populate fails to overwrite JToken value with mismatched type #2512

ejball opened this issue Apr 14, 2021 · 1 comment

Comments

@ejball
Copy link

ejball commented Apr 14, 2021

Source/destination types

class HasToken
{
	public JToken? Value { get; set; }
}

Source/destination JSON

{"value":{}}

Expected behavior

Value should be a JObject.

Actual behavior

If Value was already set to a JToken that isn't a JObject, Populate fails with this exception: JsonSerializationException: Deserialized JSON type 'Newtonsoft.Json.Linq.JObject' is not compatible with expected type 'Newtonsoft.Json.Linq.JArray'.

This started happening with 13.0.1, presumably due to #2494.

Steps to reproduce

var jToken = JToken.Parse(@"{""value"":{}}");
var hasToken = new HasToken { Value = new JArray() };
JsonSerializer.Create().Populate(jToken.CreateReader(), hasToken);
@JamesNK
Copy link
Owner

JamesNK commented May 14, 2021

Duplicate of #2529

@JamesNK JamesNK marked this as a duplicate of #2529 May 14, 2021
@JamesNK JamesNK closed this as completed May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants