Skip to content

Commit b6d3f9a

Browse files
committed
Replace NewtonsoftDataContractResolver with JsonSerializerDataContractResolver
1 parent 8d94ec9 commit b6d3f9a

File tree

4 files changed

+104
-102
lines changed

4 files changed

+104
-102
lines changed

src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public string GetSchemaId(Type type)
4646
{
4747
ArgumentGuard.NotNull(type, nameof(type));
4848

49-
ResourceContext resourceContext = _resourceGraph.GetResourceContext(type);
49+
ResourceContext resourceContext = _resourceGraph.TryGetResourceContext(type);
5050

5151
if (resourceContext != null)
5252
{

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiDataContractResolver.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using System.Text.Json;
56
using JsonApiDotNetCore.Configuration;
67
using JsonApiDotNetCore.Resources;
78
using JsonApiDotNetCore.Resources.Annotations;
8-
using Swashbuckle.AspNetCore.Newtonsoft;
99
using Swashbuckle.AspNetCore.SwaggerGen;
1010

1111
namespace JsonApiDotNetCore.OpenApi.SwaggerComponents
1212
{
1313
/// <summary>
14-
/// For schema generation, we rely on <see cref="NewtonsoftDataContractResolver" /> from Swashbuckle for all but our own JSON:API types.
14+
/// For schema generation, we rely on <see cref="JsonSerializerDataContractResolver" /> from Swashbuckle for all but our own JSON:API types.
1515
/// </summary>
1616
internal sealed class JsonApiDataContractResolver : ISerializerDataContractResolver
1717
{
18-
private readonly NewtonsoftDataContractResolver _dataContractResolver;
18+
private readonly JsonSerializerDataContractResolver _dataContractResolver;
1919
private readonly IResourceGraph _resourceGraph;
2020

2121
public JsonApiDataContractResolver(IResourceGraph resourceGraph, IJsonApiOptions jsonApiOptions)
@@ -25,8 +25,8 @@ public JsonApiDataContractResolver(IResourceGraph resourceGraph, IJsonApiOptions
2525

2626
_resourceGraph = resourceGraph;
2727

28-
var serializerOptions = jsonApiOptions.SerializerOptions;
29-
_dataContractResolver = new NewtonsoftDataContractResolver(serializerOptions);
28+
JsonSerializerOptions serializerOptions = jsonApiOptions.SerializerOptions;
29+
_dataContractResolver = new JsonSerializerDataContractResolver(serializerOptions);
3030
}
3131

3232
public DataContract GetDataContractForType(Type type)

test/OpenApiTests/LegacyOpenApiIntegration/LegacyOpenApiIntegrationStartup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json.Serialization;
12
using JetBrains.Annotations;
23
using JsonApiDotNetCore.Configuration;
34
using JsonApiDotNetCore.Resources.Annotations;
@@ -17,6 +18,7 @@ protected override void SetJsonApiOptions(JsonApiOptions options)
1718
options.DefaultAttrCapabilities = AttrCapabilities.AllowView;
1819
options.SerializerOptions.PropertyNamingPolicy = JsonKebabCaseNamingPolicy.Instance;
1920
options.SerializerOptions.DictionaryKeyPolicy = JsonKebabCaseNamingPolicy.Instance;
21+
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
2022
}
2123
}
2224
}

0 commit comments

Comments
 (0)