Skip to content

Instantly share code, notes, and snippets.

@glennblock
Created January 8, 2012 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennblock/1576925 to your computer and use it in GitHub Desktop.
Save glennblock/1576925 to your computer and use it in GitHub Desktop.
Web Api - Order formatter
public class OrderMediaTypeFormatterJson : MediaTypeFormatter
{
public OrderMediaTypeFormatter() {
SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/contoso.orders+json")
);
}
public override object OnWriteToStream(Type type, object value, System.IO.Stream stream, HttpContentHeaders contentHeaders, System.Net.TransportContext context)
{
var linkedOrder = value as ILinkable<Order>();
dynamic json = new JsonObject()
//write the order to json
}
public void OnReadFromStream(Type type, System.IO.Stream stream, HttpContentHeaders contentHeaders) {
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment