asp.net web api2 - Web API OData v2 Ignore Extra Client-Side Properties -


i curious options available me ignore additional property sent client-side ui (openui5) back-end api (asp.net web api odata v1-3).


problem

openui5 sends additional property along request causes null parameter (where i'd typically have delta<models.item> patch), , badrequest response of:

{     "error": {         "code":"",         "message":{             "lang":"en-us","value":"the request invalid."         },         "innererror":{             "message":"patch : property '__metadata' not exist on type 'models.item'. make sure use property names defined type.",             "type":"",             "stacktrace":""         }     } } 

(server side) models/item.cs

public partial class application {     public string property1 { get; set; }     public string property2 { get; set; }     public string property3 { get; set; } } 

my client-side library sending in http merge few properties changed, we're able use webapi's delta<t>.

i don't control on how request gets sent (see api documentation openui5 call here). cannot control outbound request looks (let's change property1 , property2 on object):

merge http://my-api.com/odata/items(3)

{     "property1": "abc",     "property2": "def",     "__metadata": {          "id": "http://my-api.com/odata/items(3)",         "uri": "http://my-api.com/odata/items(3)",         "type": "models.item"     } } 

which i'd sent, exception of __metadata object. saw similar post proper way (in odata v4) allow dynamicproperties (https://stackoverflow.com/a/26312571/569531). however, using ui5, restricted v2.


question

is possible implement messagehandler, modelbinder or alternative strip __metadata property before incoming request -or- during model binding? concern messagehandler not able modify incoming request body, , creating custom modelbinder might tough due type used in merge/patch request delta<t>. valueprovider implementation might struggle, open suggestions.

you make new odata model inherits original odata model. , override _request function.

var mymodel = odatamodel.extend("sap.ui.model.rest.mymodel",{   constructor : function(sserviceurl, mparameters) {     odatamodel.apply(this, arguments);   } }); mymodel.prototype._request = function(orequest, fnsuccess, fnerror) {   if (orequest.data) {     if (orequest.data.__metadata) {       delete orequest.data.__metadata;     }   }   return odatamodel.prototype._request.apply(this, [orequest, fnsuccess, fnerror]); }; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -