Monday, 15 April 2013

c# - Serializing a dynamic property to JSON -



c# - Serializing a dynamic property to JSON -

i have web api project hydrates object defined next json. attempting insert object ravendb database, finding dynamic property 'content' not beingness serialized (note empty arrays).

i have tried several serializers produce json strins: system.helpers.json.encode(), system.web.script.serialization.javascriptserializer. both suffers same problem.

ravenjobject.fromobject(obj) suffers same problem.

is there way accomplish aim in spite of apparent limitation in clr reflection?

public class sampletype { public guid? id { get; private set; } public dynamic content { get; set; } public string message { get; set; } public string actor { get; set; } public logentry() { id = guid.newguid(); } } json submitted api: { "content": { "somenumber": 5, "adate": "/date(1360640329155)/", "maybeaboolean": true, "emptyguid": "00000000-0000-0000-0000-000000000000" }, "message": "hey there", "actor": "john dow" } hydrated object: id: {b75d9134-2fd9-4c89-90f7-a814fa2f244d} content: { "somenumber": 5, "adate": "2013-02-12t04:37:44.029z", "maybeaboolean": true, "emptyguid": "00000000-0000-0000-0000-000000000000" } message: "hey there", actor: "john dow" json 3 methods: { "id": "b75d9134-2fd9-4c89-90f7-a814fa2f244d", "content": [ [ [] ], [ [] ], [ [] ], [ [] ] ], "message": "hey there", "actor": "john dow" }

your dynamic object has implement getdynamicfieldnames() method dynamic serialization work.

c# json serialization ravendb square-bracket

No comments:

Post a Comment