Revised AbpJsonOptions.

pull/653/head
Halil İbrahim Kalkan 6 years ago
parent d67be12288
commit 08fd42e1d4

@ -1,9 +1,10 @@
using Newtonsoft.Json;
namespace Volo.Abp.Json
namespace Volo.Abp.Json
{
public class AbpJsonOptions
{
public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings();
/// <summary>
/// Used to set default value for the DateTimeFormat.
/// </summary>
public string DefaultDateTimeFormat { get; set; }
}
}

@ -14,7 +14,11 @@ namespace Volo.Abp.Json.Newtonsoft
public AbpJsonIsoDateTimeConverter(IClock clock, IOptions<AbpJsonOptions> abpJsonOptions)
{
_clock = clock;
DateTimeFormat = abpJsonOptions.Value.SerializerSettings.DateFormatString;
if (abpJsonOptions.Value.DefaultDateTimeFormat != null)
{
DateTimeFormat = abpJsonOptions.Value.DefaultDateTimeFormat;
}
}
public override bool CanConvert(Type objectType)

@ -1,5 +1,4 @@
using System;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Volo.Abp.DependencyInjection;
@ -9,12 +8,10 @@ namespace Volo.Abp.Json.Newtonsoft
public class NewtonsoftJsonSerializer : IJsonSerializer, ITransientDependency
{
private readonly AbpJsonIsoDateTimeConverter _dateTimeConverter;
private readonly AbpJsonOptions _abpJsonOptions;
public NewtonsoftJsonSerializer(AbpJsonIsoDateTimeConverter dateTimeConverter, IOptions<AbpJsonOptions> abpJsonOptions)
public NewtonsoftJsonSerializer(AbpJsonIsoDateTimeConverter dateTimeConverter)
{
_dateTimeConverter = dateTimeConverter;
_abpJsonOptions = abpJsonOptions.Value;
}
public string Serialize(object obj, bool camelCase = true, bool indented = false)
@ -34,7 +31,7 @@ namespace Volo.Abp.Json.Newtonsoft
protected virtual JsonSerializerSettings CreateSerializerSettings(bool camelCase = true, bool indented = false)
{
var settings = _abpJsonOptions.SerializerSettings;
var settings = new JsonSerializerSettings();
settings.Converters.Insert(0, _dateTimeConverter);

@ -13,7 +13,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
{
services.Configure<AbpJsonOptions>(options =>
{
options.SerializerSettings.DateFormatString = "yyyy*MM*dd";
options.DefaultDateTimeFormat = "yyyy*MM*dd";
});
base.ConfigureServices(context, services);

@ -20,7 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
{
services.Configure<AbpJsonOptions>(options =>
{
options.SerializerSettings.DateFormatString = "yyyy*MM*dd";
options.DefaultDateTimeFormat = "yyyy*MM*dd";
});
base.ConfigureServices(context, services);

Loading…
Cancel
Save