-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
MvcNewtonsoftJsonOptions.cs
46 lines (40 loc) · 2.1 KB
/
MvcNewtonsoftJsonOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Newtonsoft.Json;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// Provides programmatic configuration for JSON formatters using Newtonsoft.JSON.
/// </summary>
public class MvcNewtonsoftJsonOptions : IEnumerable<ICompatibilitySwitch>
{
private readonly IReadOnlyList<ICompatibilitySwitch> _switches = Array.Empty<ICompatibilitySwitch>();
/// <summary>
/// Gets or sets a flag to determine whether error messages from JSON deserialization by the
/// <see cref="NewtonsoftJsonInputFormatter"/> will be added to the <see cref="ModelStateDictionary"/>. If
/// <see langword="false"/>, a generic error message will be used instead.
/// </summary>
/// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks>
/// Error messages in the <see cref="ModelStateDictionary"/> are often communicated to clients, either in HTML
/// or using <see cref="BadRequestObjectResult"/>. In effect, this setting controls whether clients can receive
/// detailed error messages about submitted JSON data.
/// </remarks>
public bool AllowInputFormatterExceptionMessages { get; set; } = true;
/// <summary>
/// Gets the <see cref="JsonSerializerSettings"/> that are used by this application.
/// </summary>
public JsonSerializerSettings SerializerSettings { get; } = JsonSerializerSettingsProvider.CreateSerializerSettings();
IEnumerator<ICompatibilitySwitch> IEnumerable<ICompatibilitySwitch>.GetEnumerator() => _switches.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator();
}
}