Newtonsoft.Json deserialize issue [Answered]
I have a json string. For example this one:
How can I deserialize some fields to a structure field in my class? For instance:
How can I deserialize the string to put these two fields in an
Account
field?6 Replies
You'd need a custom deserialiser for that.
https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm
afaik neither Newtonsoft, nor System.Text.Json can do what you want direclty
What I would do is have the input model flat, then transform it to your DTO manually rather than making a custom converter. (if you have no control over the input string, that is.)
Okay, thank you so much for answers
It's not about structs. It's about the target class not having the same structure than the source.
(Source has A, B, C, and the target class has A, D while D contains B, C.)
✅ This post has been marked as answered!