asp.net-web-apijson.netupshot

Converting the type information supplied by upshot js to that required by JSON.NET in a web api submit


I am attempting to use ASP.NET MVC 4 beta together with JSON.NET. I'm using upshot to talk to web api. However when upshiot does a submit it sends the type information in the change set as (for example "__type":"EquipmentClass:#RXSteps.StepModel.Equipment" instead of "$type":"RXSteps.StepModel.Equipment.EquipmentClass, RXSteps.StepModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" which is what JSON.NET wants.

at the moment I have hacked upshot with encodedChangeSet= encodedChangeSet.replace(/"__type":"EquipmentClass:#RXSteps.StepModel.Equipment"/g, '"$type":"RXSteps.StepModel.Equipment.EquipmentClass, RXSteps.StepModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"');

However I would like to know how I could do this in a generic way for any type.

many thanks


Solution

  • I would create your own UpshotJSONMediaTypeFormatter and do the conversion in there. Henrik has a post on using a JSON.NET media type formatter here. I would just customize the OnReadFromStreamAsync method to do your replace before deserializing.