Vidhyardhi Gorrepati
Vidhyardhi Gorrepati

Reputation: 682

How to remove "Field" text from every property name in web api response

I have ASP.NET web api which is returning response with property names appended with text "Field" like below

{  
   "idField":"12345",
   "activeField":true
}

The web api method returns an object created from a proxy class which is generated in Visual Studio by adding a service reference so I can't modify the class properties with attributes.

How can I remove the "Field" text from property names?

I am also having issues with the POST method where I send JSON data without "Field" text appended to the property names and I am not getting data in the method but if I append the "Field" text, it's working as expected.

Upvotes: 0

Views: 877

Answers (1)

Vidhyardhi Gorrepati
Vidhyardhi Gorrepati

Reputation: 682

It might be a one of case and applicable only for me but here is what worked for me. I added the below code in WebApiConfig class --> Register method and I get the response as expected.

( ( Newtonsoft.Json.Serialization.DefaultContractResolver ) ( config.Formatters.JsonFormatter.SerializerSettings.ContractResolver ) ).IgnoreSerializableAttribute = true;

Upvotes: 2

Related Questions