MVC4 web api returns json in this format:
{
"LastLoginTime": "2012-07-14T13:17:36.1268831-07:00",
"UserId": 1,
"Email": "[email protected]",
"FirstName": "John",
"LastName": "Smith"
}
which is just a serialization of the object model.
I need to return and accept json with a root object and a JsonResult object. Something like this (imagine a login attempt to an api):
{
"data": [
{
"success": false,
"exception": {
"message": "Either the email address does not exist or th epassword is incorrect"
}
}]
}
or for a successful authentication
{
"data": [
{
"success": true,
"account": {
"LastLoginTime": "2012-07-14T13:17:36.1268831-07:00",
"UserId": 1,
"Email": "[email protected]",
"FirstName": "John",
"LastName": "Smith"
}
}]
}
How would I go about that using a custom implementation of MediaTypeFormtatter that is used in MVC4 webapi (RC) that will allow me to format my results in the way I described?