How do I make a custom json converter for Web Api

Hi,

I build a Web Api project and we are using Database First. To serialize data I've at first used the newtonsoft converter. There I've made myself a custom converter. I don't need all elements from the database and the model is hardcoded into a DLL. So without touching the model I can serialize what I really need.

But by returning the json string it gets escaped.

I can't find any good tutorials to custom serialize objects in Web Api so I am starting to think that this is not best practice.

What I want is an Api returning values from database. But I don't want to get every item of an entity. For speed reasons it would be nice to only access "id" and "name" value instead of all values from the database object.

I hope you understand my task. I am a bit lost now.

by Daz_Didge via /r/csharp

Leave a Reply