How to serialize a c# object to Json with namespace. If it is possible some how -


base class contains property hide new property in sub class of different type. when deserializing, facing issue. cann't change name of property in c# or json can add namespace if possible.

namespace xyz {     public class     {         public icollection<xyz.organizationattribute> organizationattributes { get; set; }     } }  namespace pqr {     public class ax :     {         public new icollection<pqr.organizationattribute> organizationattributes { get; set; }     } } 

update:

    jsonconvert.serializeobject( axobject, new jsonserializersettings     {         preservereferenceshandling = preservereferenceshandling.objects,         referenceloophandling = referenceloophandling.serialize,         metadatapropertyhandling = metadatapropertyhandling.readahead,         defaultvaluehandling = defaultvaluehandling.ignore     } );      jsonconvert.deserializeobject<a>( "axjsonstring", new jsonserializersettings     {         metadatapropertyhandling = metadatapropertyhandling.readahead     } ); 

any appreciated. thanks

based on said in comments there no way have 'pqr.organizationattribute' in class that's not related json or deserialization, that's how oop works. hiding method or field in class propagates down in inheritance hierarchy therefore when talking a can't talk fields it's children ax has re-defined.

you can read more here

edit

all right got want now. use this:

public static fromjson(string input)  {     var json = jtoken.parse(input);     json["organizationattribute"].remove();     return jsonconvert.deserializeobject<a>(json.tostring()); } 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -