0

i'm trying to creating yaml file from json using with YamlDotNet library, but i need to use dynamic object because i don't know what type of object they will send me,

I created base class for serialization like this:

public class plugins
{
     public string name { get; set; }
     public object config { get; set; }
}

EDIT It worked when I edited it as StriplingWarrior said.

public class plugins
{
     public string name { get; set; }
     public IDictionary<string, object> config { get; set; }
}

EDIT 2

i don't know my json file how will be like because of that i tried to use dynamic, when i use IDictionary<string, object> it's worked but when my json data have list inside list, result again empty, how i need to change my class or i need to write my own Converter?

    {
        "name": "correlation-id",
        "config": {
            "add": {
                "headers": [
                    "content-encoding:deflate,gzip",
                    "accept-encoding:deflate,gzip;q=1.0,*;q=0.5%"
                ]
            }
        }
    }

Result:

    plugins:
    - name: correlation-id
      config:
        generator: uuid
        header_name: Aura-Correlation-Id
        echo_downstream: true
    - name: correlation-id
      config:
        config: data
        header_name: Aura-Correlation-Id
        val3: true
    - name: correlation-id
      config:
        add:
          headers:
          - []
          - []

EDIT 2 END

And my json values like that:

[
    {
        "name": "corr-id",
        "config": {
            "generator": "uuid",
            "header_name": "-Id",
            "echo_downstream": true
        }
    },
    {
        "name": "cation-id2",
        "config": {
            "val4": "val3",
            "header_name": "Aura-Id",
            "echo_downstream": true,
            "title": "kube"
        }
    },
    {
        "name": "ation-id2",
        "config": {
            "val1": "val2",
            "title": "val3"
        }
    },
    {
        "name": "ati2",
        "config": {
            "contact": "some val",
            "group": "lenght",
            "title": "transform"
        }
    }
]

Final result like that:

    plugins:

    - name: corr-id

      config:

        generator: []

        header_name: []

        echo_downstream: &o0 []

    - name: cation-id2

      config:

        val4: &o1 []

        header_name: []

        echo_downstream: *o0

        title: []

    - name: ation-id2

      config:

        val1: []

        title: *o1

    - name: ati2

      config:

        contact: []

        group: []

        title: []

I tried send to serializer json string but returned to me same data and i also tried made new JObject and add all values this object but it didnt worked.

0 Answers0