C#C
C#3y ago
Malibloo

❔ JSON Serialization Weird Model

Hey all, I have a situation where I need to approach a REST service with a POST containing either XML or JSON. However, the data that I need to input has a strange (to me) model structure that I'm not sure how I would serialize without creating a ridiculous ToString override that I'd need to recreate for every other approach that would also use similar models, which is clearly a terrible idea.
The other alternative is creating a mass amount of models with a lot of identical names which would make putting in the necessary data an absolute nightmare.
While I know the basics of json serialization, I haven't had to deal with a situation like this before. Is there any way to make this much easier, or am I just stuck with coding myself through a nightmare every single time I need to approach this service?

Example of the data in json form:
{
  "Subject": {
    "Element": {
      "@SbId": 9999,
      "Fields": {
        "StId": 0,
        "Ds": "Subject Test",
        "Da": "2022-12-30T12:00:00"
      },
      "Objects": [
        {
          "SubjectLink": {
            "Element": {
              "Fields": {
                "ToBC": false
              }
            }
          }
        },
        {
          "SubjectAttachment": {
            "Element": {
              "Fields": {
                "FileName": "Filename",
                "FileId": "0"
} } } } ] } } }
Was this page helpful?