mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-11-24 08:42:19 +02:00
json response from API are now in pascalCasing
This commit is contained in:
parent
e720094f9c
commit
9969f66201
@ -5,6 +5,7 @@
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Bootstrappers.Autofac;
|
||||
using NzbDrone.Api.ErrorManagment;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Api.Resolvers;
|
||||
@ -83,6 +84,7 @@ protected override NancyInternalConfiguration InternalConfiguration
|
||||
var internalConfig = NancyInternalConfiguration.Default;
|
||||
|
||||
internalConfig.StatusCodeHandlers.Add(typeof(ErrorHandler));
|
||||
internalConfig.Serializers.Add(typeof(NancyJsonSerializer));
|
||||
|
||||
|
||||
return internalConfig;
|
||||
|
@ -3,6 +3,7 @@
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.ErrorHandling;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
|
27
NzbDrone.Api/Extentions/NancyJsonSerializer.cs
Normal file
27
NzbDrone.Api/Extentions/NancyJsonSerializer.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Api.Extentions
|
||||
{
|
||||
public class NancyJsonSerializer : ISerializer
|
||||
{
|
||||
public readonly static NancyJsonSerializer Instance = new NancyJsonSerializer();
|
||||
|
||||
public bool CanSerialize(string contentType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Serialize<TModel>(string contentType, TModel model, Stream outputStream)
|
||||
{
|
||||
var jsonTextWriter = new JsonTextWriter(new StreamWriter(outputStream));
|
||||
Serializer.Instance.Serialize(jsonTextWriter, model);
|
||||
jsonTextWriter.Flush();
|
||||
}
|
||||
|
||||
public IEnumerable<string> Extensions { get; private set; }
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Api.QualityType
|
||||
namespace NzbDrone.Api.Extentions
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
@ -14,17 +13,12 @@ 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
|
||||
});
|
||||
return JsonConvert.DeserializeObject<T>(value, Serializer.Settings);
|
||||
}
|
||||
|
||||
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
ISerializer serializer = new DefaultJsonSerializer();
|
||||
var jsonResponse = new JsonResponse<TModel>(model, serializer) { StatusCode = statusCode };
|
||||
var jsonResponse = new JsonResponse<TModel>(model, new NancyJsonSerializer()) { StatusCode = statusCode };
|
||||
return jsonResponse;
|
||||
}
|
||||
}
|
33
NzbDrone.Api/Extentions/Serializer.cs
Normal file
33
NzbDrone.Api/Extentions/Serializer.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace NzbDrone.Api.Extentions
|
||||
{
|
||||
public static class Serializer
|
||||
{
|
||||
static Serializer()
|
||||
{
|
||||
Settings = new JsonSerializerSettings
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.None,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
|
||||
};
|
||||
|
||||
Instance = new JsonSerializer
|
||||
{
|
||||
DateTimeZoneHandling = Settings.DateTimeZoneHandling,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.None,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
}
|
||||
|
||||
public static JsonSerializerSettings Settings { get; private set; }
|
||||
|
||||
public static JsonSerializer Instance { get; private set; }
|
||||
}
|
||||
}
|
@ -89,6 +89,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extentions\NancyJsonSerializer.cs" />
|
||||
<Compile Include="Extentions\Serializer.cs" />
|
||||
<Compile Include="QualityProfiles\RootFolderModule.cs" />
|
||||
<Compile Include="Series\SeriesModule.cs" />
|
||||
<Compile Include="ErrorManagment\ApiException.cs" />
|
||||
@ -103,7 +105,7 @@
|
||||
<Compile Include="QualityProfiles\QualityProfilesModule.cs" />
|
||||
<Compile Include="QualityType\QualityTypeModel.cs" />
|
||||
<Compile Include="QualityType\QualityTypeModule.cs" />
|
||||
<Compile Include="QualityType\RequestExtensions.cs" />
|
||||
<Compile Include="Extentions\RequestExtensions.cs" />
|
||||
<Compile Include="Resolvers\AllowedToQualitiesResolver.cs" />
|
||||
<Compile Include="Resolvers\QualitiesToAllowedResolver.cs" />
|
||||
<Compile Include="Resolvers\QualityTypesToIntResolver.cs" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user