JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.73k stars 3.25k forks source link

Enable roundtrip for F# struct record with datamember attribute #2860

Open T-Gro opened 1 year ago

T-Gro commented 1 year ago

This addresses #1295 , specifically the part which started to regress after F#7 added the "readonly" modified to compiler generated records.

The solution is to adjust the heuristic in order to find a good fitting parametrized constructor, and avoid fallback to default one. Why did this work before? Because a default constructor was used, and private property/field injected later. However, with the "readonly" modifier, field injection no longer works.

This was always working fine without using mapping attributes, because newtonsoft found a constructor argument by its name. The change in this PR just extends this to also look for constructor argument using the underlying name, and not just the name of the JSON property.

T-Gro commented 1 year ago

Hi all, is there anything else I should improve here, or is this ready to be merged now?

JamesNK commented 1 year ago

I need time to think this through and understand what breaking changes it could cause. I'm really busy right now, so I don't know when I'll get to that.

T-Gro commented 10 months ago

@JamesNK : Hi James, would now be a better time to merge this in please?