Skip to content

Commit 0c0690e

Browse files
Bart Koelmanmaurei
andauthored
Merge master into openapi (#1086)
* Removed temporary workaround to start postgres service in cibuild (#1083) * Restored docs for HasManyThrough, which was removed in #1037 (#1084) * Use System.Text.Json (#1075) * Removed Serialization.Client.Internal * Removed undocumented ?nulls and ?defaults query string support * Refactor: use interpolated strings instead of concatenation * Updated tests to use string value for IDs; centralized pseudo-constants * Added tests for pascal casing * Optimized attribute/relationship lookups * Breaking: Made IResourceContextProvider.GetResourceContext() throw when not found; added TryGetResourceContext() that returns null * Optimized resource graph lookups * Breaking: Merged IResourceContextProvider into IResourceGraph * Switched to STJ in assertions Note we need JsonDateTimeOffsetFormatSpecifier now, because STJ never tries to infer the CLR type from JSON values between quotes, while Newtonsoft does. So Newtonsoft would convert both values to date/time, effectively hiding the textual difference that was always there. * Switched to STJ in rendering exception stack traces * Switched to STJ in rendering CLR objects as part of tracing. STJ properly handles self-referencing EF Core objects when enabling reference tracking, as opposed to Newtonsoft. * Switched to STJ in attribute change tracking. This used to take options into account, which is unneeded because we only care about whether there's a diff, not so much what that diff looks like. And we don't expect self-references here (it would have crashed in the past, and will now too). * Switched to STJ in Microservices example * Removed re-indent of response body on HTTP status code mismatch in tests, because we already use indenting in TestableStartup, so this is no longer needed. * Use STJ naming convention on special-cased code paths * Renamed RelationshipEntry to RelationshipObject, Error to ErrorObject * Fix broken test in cibuild * Fixed broken tests in cibuild due to different line endings * Package updates * Refactor serialization objects - Simplified error objects, so they are similar to the other serialization objects. This means no default instances, constructors (exception: ErrorObject) or conditional serialization logic. And explicit names to overrule naming conventions. And annotations to skip serialization when null. - Added missing members from JSON:API v1.1 spec: ErrorDocument.Meta, ErrorLinks.Type, ErrorSource.Header, ResourceIdentifierObject.Meta - Normalized collection types - Updated documentation: Link to v1.1 of JSON:API spec instead of copy/pasted text * Merged ErrorDocument and AtomicOperationsDocument into Document Bugfix: jsonapi/version was missing in error responses * Fill error.source.header where applicable * Breaking: Renamed "total-resources" meta key to "total" because thats what Ember.js expects it to be named (see https://guides.emberjs.com/release/models/handling-metadata/) * Removed unneeded StringEnumConverter usage. Also removed it from the defaults for tests, because that hides the problem when we forget to put it on a member that needs it. * Use configured STJ options for null/default value inclusion Bugfix: do not break out of method on first attribute * Fixed data type in json request body * Added missing type, which is a required element * Converted core code to use System.Text.Json - Added various converters to steer JsonSerializer in the right direction - JsonApiDotNetCore.Serialization.Objects - Removed inheritance in JsonApiDotNetCore.Serialization.Objects, so we're in control of element write order - Moved "meta" to the end in all types (it is secondary information) - Consistently set IgnoreCondition on all properties, so we don't need to override global options anymore * Updated documentation * Fixed broken example-generation. Set launchBrowser to true, so it shows sample data on F5. * Inlined properties on serializable objects * Add test for incompatible ID value. By default, this produces: ``` The JSON value could not be converted to JsonApiDotNetCore.Serialization.Objects.SingleOrManyData`1[JsonApiDotNetCore.Serialization.Objects.ResourceObject]. Path: $.data | LineNumber: 3 | BytePositionInLine: 11. ``` which is totally unhelpful. Because this is so likely to hit users, we special-case here to produce a better error. * Removed misplaced launchsettings.json * Review feedback: use base class instead of static helper * Update ROADMAP.md * Post-merge fixes * Replace NewtonsoftDataContractResolver with JsonSerializerDataContractResolver * Small cleanups Co-authored-by: maurei <[email protected]>
1 parent 362bf5f commit 0c0690e

File tree

330 files changed

+6223
-6917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

330 files changed

+6223
-6917
lines changed

Directory.Build.props

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
<SwashbuckleVersion>6.2.*</SwashbuckleVersion>
88
<JsonApiDotNetCoreVersionPrefix>4.2.0</JsonApiDotNetCoreVersionPrefix>
99
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
10+
<WarningLevel>9999</WarningLevel>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
1314
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="All" />
14-
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.6.0" PrivateAssets="All" />
15+
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.7.0" PrivateAssets="All" />
1516
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
1617
</ItemGroup>
1718

@@ -23,11 +24,11 @@
2324

2425
<!-- Test Project Dependencies -->
2526
<PropertyGroup>
26-
<BogusVersion>33.0.2</BogusVersion>
27+
<BogusVersion>33.1.1</BogusVersion>
2728
<CoverletVersion>3.1.0</CoverletVersion>
28-
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
29+
<FluentAssertionsVersion>6.1.0</FluentAssertionsVersion>
2930
<MoqVersion>4.16.1</MoqVersion>
3031
<XUnitVersion>2.4.*</XUnitVersion>
31-
<TestSdkVersion>16.10.0</TestSdkVersion>
32+
<TestSdkVersion>16.11.0</TestSdkVersion>
3233
</PropertyGroup>
3334
</Project>

ROADMAP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ The need for breaking changes has blocked several efforts in the v4.x release, s
1919
- [x] Tweak trace logging [#1033](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1033)
2020
- [x] Instrumentation [#1032](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1032)
2121
- [x] Optimized delete to-many [#1030](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1030)
22-
- [ ] Support System.Text.Json [#664](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/664) [#999](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/999) [#233](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/233)
23-
- [ ] Optimize IIdentifiable to ResourceObject conversion [#1028](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1028) [#1024](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1024)
22+
- [x] Support System.Text.Json [#664](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/664) [#999](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/999) [1077](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1077) [1078](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1078)
23+
- [ ] Optimize IIdentifiable to ResourceObject conversion [#1028](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1028) [#1024](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1024) [#233](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/233)
2424
- [ ] Nullable reference types [#1029](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1029)
2525

2626
Aside from the list above, we have interest in the following topics. It's too soon yet to decide whether they'll make it into v5.x or in a later major version.

appveyor.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ for:
3535
only:
3636
- image: Visual Studio 2019
3737
services:
38-
- postgresql134
39-
# https://help.appveyor.com/discussions/problems/30239-postgres-fails-to-connect-after-version-change
40-
init:
41-
- net start postgresql-x64-13
38+
- postgresql13
4239
# REF: https://github.com/docascode/docfx-seed/blob/master/appveyor.yml
4340
before_build:
4441
- pwsh: |

benchmarks/DependencyFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ internal sealed class DependencyFactory
88
public IResourceGraph CreateResourceGraph(IJsonApiOptions options)
99
{
1010
var builder = new ResourceGraphBuilder(options, NullLoggerFactory.Instance);
11+
1112
builder.Add<BenchmarkResource>(BenchmarkResourcePublicNames.Type);
13+
builder.Add<SubResource>();
14+
1215
return builder.Build();
1316
}
1417
}

benchmarks/Query/QueryParserBenchmarks.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ private static QueryStringReader CreateQueryParameterDiscoveryForAll(IResourceGr
6464
var sortReader = new SortQueryStringParameterReader(request, resourceGraph);
6565
var sparseFieldSetReader = new SparseFieldSetQueryStringParameterReader(request, resourceGraph);
6666
var paginationReader = new PaginationQueryStringParameterReader(request, resourceGraph, options);
67-
var defaultsReader = new DefaultsQueryStringParameterReader(options);
68-
var nullsReader = new NullsQueryStringParameterReader(options);
6967

7068
IQueryStringParameterReader[] readers = ArrayFactory.Create<IQueryStringParameterReader>(includeReader, filterReader, sortReader,
71-
sparseFieldSetReader, paginationReader, defaultsReader, nullsReader);
69+
sparseFieldSetReader, paginationReader);
7270

7371
return new QueryStringReader(options, queryStringAccessor, readers, NullLoggerFactory.Instance);
7472
}

benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.ComponentModel.Design;
2+
using System.Text.Json;
43
using BenchmarkDotNet.Attributes;
54
using JsonApiDotNetCore.Configuration;
65
using JsonApiDotNetCore.Middleware;
76
using JsonApiDotNetCore.Resources;
87
using JsonApiDotNetCore.Serialization;
9-
using JsonApiDotNetCore.Serialization.Objects;
108
using Microsoft.AspNetCore.Http;
11-
using Newtonsoft.Json;
129

1310
namespace Benchmarks.Serialization
1411
{
1512
// ReSharper disable once ClassCanBeSealed.Global
1613
[MarkdownExporter]
1714
public class JsonApiDeserializerBenchmarks
1815
{
19-
private static readonly string Content = JsonConvert.SerializeObject(new Document
16+
private static readonly string RequestBody = JsonSerializer.Serialize(new
2017
{
21-
Data = new ResourceObject
18+
data = new
2219
{
23-
Type = BenchmarkResourcePublicNames.Type,
24-
Id = "1",
25-
Attributes = new Dictionary<string, object>
20+
type = BenchmarkResourcePublicNames.Type,
21+
id = "1",
22+
attributes = new
2623
{
27-
["name"] = Guid.NewGuid().ToString()
2824
}
2925
}
3026
});
@@ -55,7 +51,7 @@ public JsonApiDeserializerBenchmarks()
5551
[Benchmark]
5652
public object DeserializeSimpleObject()
5753
{
58-
return _jsonApiDeserializer.Deserialize(Content);
54+
return _jsonApiDeserializer.Deserialize(RequestBody);
5955
}
6056
}
6157
}

benchmarks/Serialization/JsonApiSerializerBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public JsonApiSerializerBenchmarks()
3434
ILinkBuilder linkBuilder = new Mock<ILinkBuilder>().Object;
3535
IIncludedResourceObjectBuilder includeBuilder = new Mock<IIncludedResourceObjectBuilder>().Object;
3636

37-
var resourceObjectBuilder = new ResourceObjectBuilder(resourceGraph, new ResourceObjectBuilderSettings());
37+
var resourceObjectBuilder = new ResourceObjectBuilder(resourceGraph, options);
3838

3939
IResourceDefinitionAccessor resourceDefinitionAccessor = new Mock<IResourceDefinitionAccessor>().Object;
4040

docs/request-examples/012_PATCH_Book.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ curl -s -f http://localhost:14141/api/books/1 `
44
-d '{
55
\"data\": {
66
\"type\": \"books\",
7-
\"id\": "1",
7+
\"id\": \"1\",
88
\"attributes\": {
99
\"publishYear\": 1820
1010
}

docs/usage/options.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,26 @@ To limit the maximum depth of nested includes, use `MaximumIncludeDepth`. This i
7878
options.MaximumIncludeDepth = 1;
7979
```
8080

81-
## Custom Serializer Settings
81+
## Customize Serializer options
8282

83-
We use [Newtonsoft.Json](https://www.newtonsoft.com/json) for all serialization needs.
84-
If you want to change the default serializer settings, you can:
83+
We use [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) for all serialization needs.
84+
If you want to change the default serializer options, you can:
8585

8686
```c#
87-
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
88-
options.SerializerSettings.Converters.Add(new StringEnumConverter());
89-
options.SerializerSettings.Formatting = Formatting.Indented;
87+
options.SerializerOptions.WriteIndented = true;
88+
options.SerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
89+
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
9090
```
9191

9292
The default naming convention (as used in the routes and resource/attribute/relationship names) is also determined here, and can be changed (default is camel-case):
9393

9494
```c#
95-
options.SerializerSettings.ContractResolver = new DefaultContractResolver
96-
{
97-
NamingStrategy = new KebabCaseNamingStrategy()
98-
};
95+
// Use Pascal case
96+
options.SerializerOptions.PropertyNamingPolicy = null;
97+
options.SerializerOptions.DictionaryKeyPolicy = null;
9998
```
10099

101-
Because we copy resource properties into an intermediate object before serialization, Newtonsoft.Json annotations on properties are ignored.
100+
Because we copy resource properties into an intermediate object before serialization, JSON annotations such as `[JsonPropertyName]` and `[JsonIgnore]` on `[Attr]` properties are ignored.
102101

103102

104103
## Enable ModelState Validation

docs/usage/resource-graph.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ public class MyModel : Identifiable
9898
}
9999
```
100100

101-
The default naming convention can be changed in [options](~/usage/options.md#custom-serializer-settings).
101+
The default naming convention can be changed in [options](~/usage/options.md#customize-serializer-options).

0 commit comments

Comments
 (0)