c# - Deserialize derived classes using Json.net without using JObject -


i have large json dataset need deserialize. using json.net's jsontextreader read data.

my problem need deserialize derived classes, need able "look ahead" particular property defining data type. in example below, "type" parameter used determine object type deserialize.

{   type: "groupdata",   groupparam: "groupvalue1",   nestedobject:    {     type: "groupdata",     groupparam: "groupvalue2",     nestedobject:     {       type: "bigdata",       arraydata: [ ... ]     }   } 

my derived objects can heavily nested , deep. loading entire dataset in memory not desired since require memory. once down "bigdata" object, processing data (such array in example above), not stored in memory (it big).

all solutions problem have seen far have utilized jobject deserialize partial objects. want avoid using jobject because deserialize every object down hierarchy repeatedly.

how can solve deserialization issue?

is there way search ahead "type" parameter, backtrack start of object's { character start processing?

i not aware of anyway prempt loading in of object in order specify lookahead (at least not in json.net) use other attribute based configuration items @ disposal in order ignore unwanted properties:

public class groupdata {     [jsonignore]     public string groupparam { get; set; }     [jsonignore]     public groupdata nestedobject { get; set; }      public string[] arraydata { get; set; } } 

alternatively, can give custom creation converters try:

for example..

public class groupdata {     [jsonignore]     public string groupparam { get; set; }     [jsonignore]     public groupdata nestedobject { get; set; } }  public class bigdata : groupdata {     public string[] arraydata { get; set; } }  public class objectconverter<t> : customcreationconverter<t> {     public objectconverter() { }      public override bool canconvert(type objecttype)     {         return objecttype.name == "bigdata";     }      public override object readjson(jsonreader reader, type objecttype, object existingvalue, jsonserializer serializer)     {         // additional checks/work?        serializer.populate(reader, target);     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -