2013-01-19 01:27:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.Responses;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.QualityType
|
|
|
|
|
{
|
|
|
|
|
public static class JsonExtensions
|
|
|
|
|
{
|
|
|
|
|
public static T FromJson<T>(this Stream body)
|
|
|
|
|
{
|
|
|
|
|
var reader = new StreamReader(body, true);
|
|
|
|
|
body.Position = 0;
|
|
|
|
|
var value = reader.ReadToEnd();
|
|
|
|
|
return JsonConvert.DeserializeObject<T>(value, new JsonSerializerSettings
|
|
|
|
|
{
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore,
|
|
|
|
|
MissingMemberHandling = MissingMemberHandling.Ignore
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 04:46:43 +00:00
|
|
|
|
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
|
|
|
|
ISerializer serializer = new DefaultJsonSerializer();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
var jsonResponse = new JsonResponse<TModel>(model, serializer) { StatusCode = statusCode };
|
2013-01-19 01:27:30 +00:00
|
|
|
|
return jsonResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|