3

I want to serialize and deserialize an ExpandoObject with non-trivial values. Some values of the ExpandoObject contain objects with properties leading to circular references.

I wrote a custom serializer/deserializer for these objects. These objects however occur on many places within the ExpandoObject (also nested, not only on the root-level). But they always have the same key! I want the deserializer to take my custom deserializer for every property of the ExpandoObject of a certain key.

For example:

{
    "a": 12.5,
    "b": "hello world",
    "special": { /* ... */ },
    "c": -4,
    "d":
        {
            "x": "test",
            "special":  { /* ... */ },
            "y": 152
        },
    "e": 9053
}

I want every property special to be deserialized with my custom deserializer to my class. Everything else should be handled by the default deserializer.

Am I on the right track to handle my kind of problem? If yes, how can I achieve this using JSON.NET?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
user2033412
  • 1,950
  • 2
  • 27
  • 47
  • Show the code of your serializer and how you call it. – CodeCaster Jul 27 '15 at 14:03
  • I called it explicitly for test-purposes on the specialObjects. The json-output matches the desired structure. Deserialization also works. I did _not_ run the whole ExpandoObject through the serializer. – user2033412 Jul 27 '15 at 14:16
  • Is this a duplicate of https://stackoverflow.com/questions/30046428/json-net-deserialization-into-dynamic-object-with-referencing? – dbc Jul 27 '15 at 18:15

0 Answers0