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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With