NJsonSchema icon indicating copy to clipboard operation
NJsonSchema copied to clipboard

The JsonProperty("<name>") attribute is not used when invoked in MS Unit Test v2 project

Open markus-ja opened this issue 4 years ago • 4 comments

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.

markus-ja avatar Mar 04 '20 09:03 markus-ja

Have you tried to directly reference the (latest) newtonsoft version in the test project?

RicoSuter avatar Mar 04 '20 21:03 RicoSuter

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.

markus-ja avatar Mar 05 '20 06:03 markus-ja

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 avatar Mar 05 '20 23:03 RicoSuter

@RicoSuter @markledwich2 is there any workaround for this issue?

sherazlodhi avatar Oct 04 '21 08:10 sherazlodhi