2021年1月19日星期二

(De)serializing child JSON attributes into class properties

Let's say I have a controller which accepts the following JSON:

{      "propA": "val1",      "propB": {          "propC": "valC",          "propD": "valD"      },      "propE", "valE"  }  

Without using a custom serializer, is there a way to deserialize this JSON into a class such as:

public record Payload(      string PropA,      string PropC,      string PropD,      string PropE  );  

The JSON object "PropB" should be unwrapped, and the two child attributes "PropC" and "PropD" mapped directly to the corresponding properties of the class.

I'm using the built-in JSON classes from System.Text.

https://stackoverflow.com/questions/65804035/deserializing-child-json-attributes-into-class-properties January 20, 2021 at 02:17PM

没有评论:

发表评论