F#WebAPI默认反序列化生成@符号(F# WebAPI default deserialization producing @ sign)
我正在开发一个F#Web API应用程序 - https://github.com/odytrice/Dumia
当我尝试发送以下记录的数组时,
[<CLIMutable>] type Product = { ProductID : int Code : string Name : string Price : decimal ImageUrl : string } [<CLIMutable>] type Inventory = { Product: Product Quantity: int }这是我当前的WebAPI配置
let registerWebApi (app:IAppBuilder) = let config = new HttpConfiguration() // Configure routing config.MapHttpAttributeRoutes() // Remove XML Formatter config.Formatters.Clear() let formatter = new JsonMediaTypeFormatter() formatter.UseDataContractJsonSerializer <- false config.Formatters.Add(formatter) config.Services.Replace(typeof<IHttpControllerActivator>, CompositionRoot()) app.UseWebApi(config)我的Web API正在生成以下输出
{ Product@: { ProductID@: 1, Code@: "Bag-01", Name@: "Ladies Bag", Price@: 120, ImageUrl@: "/content/images/bag.jpg" }, Quantity@: 15 }有没有人知道如何摆脱@符号?
I'm working on an F# Web API application - https://github.com/odytrice/Dumia
When I try to send an Array of the following records,
[<CLIMutable>] type Product = { ProductID : int Code : string Name : string Price : decimal ImageUrl : string } [<CLIMutable>] type Inventory = { Product: Product Quantity: int }Here is my current WebAPI Configuration
let registerWebApi (app:IAppBuilder) = let config = new HttpConfiguration() // Configure routing config.MapHttpAttributeRoutes() // Remove XML Formatter config.Formatters.Clear() let formatter = new JsonMediaTypeFormatter() formatter.UseDataContractJsonSerializer <- false config.Formatters.Add(formatter) config.Services.Replace(typeof<IHttpControllerActivator>, CompositionRoot()) app.UseWebApi(config)My Web API is producing the following output
{ Product@: { ProductID@: 1, Code@: "Bag-01", Name@: "Ladies Bag", Price@: 120, ImageUrl@: "/content/images/bag.jpg" }, Quantity@: 15 }Does anyone have an idea how to get rid of the @ sign?
最满意答案
问题是由于WebAPI使用的默认DataContract。
我不得不改变它
config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.DefaultContractResolver()还是更好
config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.CamelCasePropertyNamesContractResolver()The Problem is because of the Default DataContract used by WebAPI.
I had to change it to
config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.DefaultContractResolver()or better yet
config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.CamelCasePropertyNamesContractResolver()更多推荐
发布评论