c# - why is concrete object being set to null in controller method? -
when send request controller, reason assigns null values object:
the request sending follows:
{ "createcustomerpaymentprofilerequest": { "merchantauthentication": { "name": "3efsw3sd66", "transactionkey": "7m444433g" }, "customerprofileid": "10000", "paymentprofile": { "billto": { "firstname": "john", "lastname": "doe", "address": "123 main st.", "city": "bellevue", "state": "wa", "zip": "98004", "country": "usa", "phonenumber": "000-000-0000" }, "payment": { "creditcard": { "cardnumber": "4111111111111111", "expirationdate": "2023-12" } }, "defaultpaymentprofile": false }, "validationmode": "livemode" } }
this how issue request postman:
why properties of request being set null?
the class defined as:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("xsd", "2.0.50727.3038")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(anonymoustype=true, namespace="anetapi/xml/v1/schema/anetapischema.xsd")] [system.xml.serialization.xmlrootattribute(namespace="anetapi/xml/v1/schema/anetapischema.xsd", isnullable=false)] public partial class createcustomerpaymentprofilerequest : anetapirequest { /// <remarks/> public string customerprofileid; /// <remarks/> public customerpaymentprofiletype paymentprofile; /// <remarks/> public validationmodeenum validationmode; /// <remarks/> [system.xml.serialization.xmlignoreattribute()] public bool validationmodespecified; }
its parent defined as:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("xsd", "2.0.50727.3038")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="anetapi/xml/v1/schema/anetapischema.xsd")] public partial class anetapirequest { /// <remarks/> public merchantauthenticationtype merchantauthentication; /// <remarks/> public string clientid; /// <remarks/> public string refid; }
and 1 of properties defined as:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("xsd", "2.0.50727.3038")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="anetapi/xml/v1/schema/anetapischema.xsd")] public partial class merchantauthenticationtype { /// <remarks/> public string name; /// <remarks/> [system.xml.serialization.xmlelementattribute("accesstoken", typeof(string))] [system.xml.serialization.xmlelementattribute("clientkey", typeof(string))] [system.xml.serialization.xmlelementattribute("fingerprint", typeof(fingerprinttype))] [system.xml.serialization.xmlelementattribute("impersonationauthentication", typeof(impersonationauthenticationtype))] [system.xml.serialization.xmlelementattribute("password", typeof(string))] [system.xml.serialization.xmlelementattribute("sessiontoken", typeof(string))] [system.xml.serialization.xmlelementattribute("transactionkey", typeof(string))] [system.xml.serialization.xmlchoiceidentifierattribute("itemelementname")] public object item; /// <remarks/> [system.xml.serialization.xmlignoreattribute()] public itemchoicetype itemelementname; /// <remarks/> public string mobiledeviceid; }
and one:
public partial class customerpaymentprofiletype : customerpaymentprofilebasetype { /// <remarks/> public paymenttype payment; /// <remarks/> public driverslicensetype driverslicense; /// <remarks/> public string taxid; /// <remarks/> public bool defaultpaymentprofile; /// <remarks/> [system.xml.serialization.xmlignoreattribute()] public bool defaultpaymentprofilespecified; }
the json being sent 1 level deep.
the payload should
{ "merchantauthentication": { "name": "3efsw3sd66", "transactionkey": "7m444433g" }, "customerprofileid": "10000", "paymentprofile": { "billto": { "firstname": "john", "lastname": "doe", "address": "123 main st.", "city": "bellevue", "state": "wa", "zip": "98004", "country": "usa", "phonenumber": "000-000-0000" }, "payment": { "creditcard": { "cardnumber": "4111111111111111", "expirationdate": "2023-12" } }, "defaultpaymentprofile": false }, "validationmode": "livemode" }
otherwise in order match json have there model have this
public class example { public createcustomerpaymentprofilerequest createcustomerpaymentprofilerequest { get; set; } }
Comments
Post a Comment