c# - JavaScriptSerializer has registerconverters, how to call base deserialize method in RegisterConverts Class -
i have javascriptserializer registerconverters class serialize datatime. in same class have deserialize
method throws notimplementedexception
. registerconverters
class working fine when serializing object.
when using same javascriptserializer
object deserialize json object required class object throwing notimplementedexception
.
here don't want use deserilize
method of registerconverters
class. how can achive that? work new javascriptserializer
object has no registerconverters
when deserializing.
public class defaultnullpropertiesconverter : javascriptconverter { public override object deserialize(idictionary<string, object> dictionary, type type, javascriptserializer serializer) { throw new notimplementedexception(); } public override idictionary<string, object> serialize(object obj, javascriptserializer serializer) { var jsonexample = new dictionary<string, object>(); foreach (var prop in obj.gettype().getproperties()) { //check if decorated scriptignore attribute bool ignoreprop = prop.isdefined(typeof(scriptignoreattribute), true); var value = prop.getvalue(obj, bindingflags.public, null, null, null); if (value != null && !ignoreprop) { if (value.gettype().fullname == "system.datetime" && convert.todatetime(value) == datetime.minvalue) continue; else if (value.gettype().fullname == "system.datetime") jsonexample.add(prop.name, convert.todatetime(value).tostring("yyyy-mm-dd")); else jsonexample.add(prop.name, value); } } return jsonexample; } public override ienumerable<type> supportedtypes { { return gettype().assembly.gettypes(); } } }
now when call deserialize method:
var restgeocoderesponse rgcr = jss.deserialize<restgeocoderesponse>(result);
this should not call deserialize method of defaultnullpropertiesconverter class. deserialize doesnot have registerconverts.
so first question ask passing registerconverters method? did write own javascriptconverter handle datetime serialization , deserialization. if javascriptconverter class wrote has throws notimplementedexception in deserialize method.
if using 3rd party javascriptconverter @ source code or if not have source code decompile source using tool dotpeek jetbrains or justdecompile telerik
Comments
Post a Comment