François
François

Reputation: 3274

Json deserializing Tuples with named variables

I have the following property in a DTO:

public IReadOnlyList<(int MyNameA, int MyNameB)> Occurences { get; set; }

If I send the following json payload to my MVC controller it woks:

"Occurences":[{"Item1" : 10, "Item2" : 2}]

however if I send the following then the controller sees (0,0) rather than (10,2):

"Occurences":[{"MyNameA" : 10, "MyNameB" : 2}]

Upvotes: 1

Views: 1506

Answers (1)

ObiEff
ObiEff

Reputation: 650

Newtonsoft.Json does not yet have support for C#7 tuples, you can track progress via this GitHub issue: https://github.com/JamesNK/Newtonsoft.Json/issues/1230.

I suggest you continute to pass it in as the first example, if you really need it to be named as MyNameA and MyNameB then you could just create a new tuple from the old one.

Upvotes: 1

Related Questions