NJsonSchema
NJsonSchema copied to clipboard
The JsonProperty("<name>") attribute is not used when invoked in MS Unit Test v2 project
Hello,
when using Newtonsoft.Json v10 or higher, the NJsonSchema.FromType<> doesn't take the json property name from the attribute. This happens only when code is invoked from the MS Unit Test project (.NetFramework).
class Person { [JsonProperty("first_name")] public string FirstName { get; set; } }
JsonSchema schema = JsonSchema.FromType<Person>(); var actual = schema.ToJson();
JsonConvert.DeserializeObject<Person>(jsonData)
...is wokring as expected.
Have you tried to directly reference the (latest) newtonsoft version in the test project?
Yes, I tried the latest newtonsoft version. Interestingly, the DataContract and DataMember attributes are working fine. Its just he JsonProperty, which is not working (only in MS Unit Test project). Using Newtonsoft.Json directly to deserialize or serialize an object, this is also working.
I think i saw this problem a long time ago - something with wrong binging redirects, ie GetCustomAttributes<JsonPropertyAttribute>() doesnt return any even if there are some (assembly version mismatch).
@RicoSuter @markledwich2 is there any workaround for this issue?