Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign conversion between JSON objects and ASP.NET models #1091

Merged
merged 49 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8534c41
Replaced suppression with fix
Sep 20, 2021
f502628
Fixed: do not duplicate the list of JSON:API errors in meta stack tra…
Sep 20, 2021
afe119d
Breaking: Added option to write request body in meta when unable to r…
Sep 20, 2021
2b47438
Breaking: Added option to allow unknown attribute/relationship keys i…
Sep 22, 2021
2b1c32b
Fixed invalid test
Sep 23, 2021
0192e39
Rewrite of reading the request body and converting it into models.
Sep 29, 2021
d247ba2
Updated error message for unknown attribute/relationship
Sep 29, 2021
8dbafd2
Updated error message for unknown resource type
Sep 29, 2021
d243dc3
Unified error messages about the absense or presense of 'id' and 'lid'
Sep 29, 2021
4c3bf71
Unified error messages about the absense of 'type'
Sep 29, 2021
1700c00
Unified error messages about incompatible types
Sep 29, 2021
d4549e8
Revert the use of different exception, because this way the request b…
Sep 29, 2021
c2e31d3
Unified error messages about mismatches in 'id' and 'lid' values
Sep 29, 2021
5ea961f
Additional unification of error messages
Sep 29, 2021
6244ef7
Unified error messages for failed type conversion
Sep 29, 2021
72f02b0
Fix cibuild
Sep 30, 2021
fe10147
Unified error messages about data presense and its value: null/object…
Sep 30, 2021
2322ac8
Unified remaining error messages
Sep 30, 2021
d254ac9
Sealed types and reduced dependencies
Sep 30, 2021
0923c8b
Fixed broken test on linux
Sep 30, 2021
6e0d287
Adapter renames:
Oct 1, 2021
169acc7
Added missing assertions on request body in error meta
Oct 1, 2021
317f293
Refactorings:
Oct 1, 2021
65b1f03
Enhanced existing tests: Assert on resource type when `included` cont…
Oct 2, 2021
5198265
Fixed the number of resource definition callbacks for sparse fieldsets
Oct 4, 2021
64cc4e2
Refactor: removed OperationContainer.Kind because IJsonApiRequest.Wri…
Oct 4, 2021
1e6d18e
Added test to capture the current behavior to return data:null for vo…
Oct 4, 2021
cab3dc6
Improved tests for includes
Oct 5, 2021
d8510aa
Rewrite of rendering the response body from models
Oct 5, 2021
055b93f
Avoid closure in hot code path to reduce allocations
Oct 6, 2021
a7c6009
Cleanup reader and writer
Oct 6, 2021
428b06b
Removed old code
Oct 6, 2021
05f155e
Fixed: crash in test serializer on assertion failure
Oct 6, 2021
fbdcefb
Removed RequestScopedServiceProvider
Oct 6, 2021
7fcb58e
Use sets for include expressions
Oct 6, 2021
f8d71f2
Fixed: return Content-Length header in HEAD response
Oct 6, 2021
ff763f1
Reorganized JADNC.Serialization namespace
Oct 6, 2021
80fe2b2
Created custom exception for remaining errors
Oct 6, 2021
f6caf3a
Fixed: call ResourceDefinition.OnApplyIncludes for all children, even…
Oct 6, 2021
0efde1b
Renamed ResourceContext to ResourceType and exposed it through relati…
Oct 7, 2021
f7e7da4
Moved logic to build resource graph from DbContext into ResourceGraph…
Oct 8, 2021
3d98057
Opened up ResponseModelAdapter for extensibility
Oct 8, 2021
2e3659f
Check off roadmap entry
Oct 11, 2021
2c4e75c
Review feedback
Oct 20, 2021
7158595
Simplified existing tests
Oct 25, 2021
7c6684f
Added extra test for data:null in relationship
Oct 25, 2021
4a8bfdd
Added test for broken resource linkage
Oct 25, 2021
0f41f85
Ported existing unit tests and changed how included[] is built.
Oct 26, 2021
5dfb6ea
Fixed cibuild
Oct 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The need for breaking changes has blocked several efforts in the v4.x release, s
- [x] Instrumentation [#1032](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1032)
- [x] Optimized delete to-many [#1030](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1030)
- [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)
- [ ] 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)
- [x] 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)
- [ ] Nullable reference types [#1029](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1029)

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.
Expand Down
122 changes: 122 additions & 0 deletions benchmarks/Deserialization/DeserializationBenchmarkBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Text.Json;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;
using JsonApiDotNetCore.Serialization.JsonConverters;
using JsonApiDotNetCore.Serialization.Request.Adapters;
using Microsoft.Extensions.Logging.Abstractions;

namespace Benchmarks.Deserialization
{
public abstract class DeserializationBenchmarkBase
{
protected readonly JsonSerializerOptions SerializerReadOptions;
protected readonly DocumentAdapter DocumentAdapter;

protected DeserializationBenchmarkBase()
{
var options = new JsonApiOptions();
IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<ResourceA>().Build();
options.SerializerOptions.Converters.Add(new ResourceObjectConverter(resourceGraph));
SerializerReadOptions = ((IJsonApiOptions)options).SerializerReadOptions;

var serviceContainer = new ServiceContainer();
var resourceFactory = new ResourceFactory(serviceContainer);
var resourceDefinitionAccessor = new ResourceDefinitionAccessor(resourceGraph, serviceContainer);

serviceContainer.AddService(typeof(IResourceDefinitionAccessor), resourceDefinitionAccessor);
serviceContainer.AddService(typeof(IResourceDefinition<ResourceA>), new JsonApiResourceDefinition<ResourceA>(resourceGraph));

// ReSharper disable once VirtualMemberCallInConstructor
JsonApiRequest request = CreateJsonApiRequest(resourceGraph);
var targetedFields = new TargetedFields();

var resourceIdentifierObjectAdapter = new ResourceIdentifierObjectAdapter(resourceGraph, resourceFactory);
var relationshipDataAdapter = new RelationshipDataAdapter(resourceIdentifierObjectAdapter);
var resourceObjectAdapter = new ResourceObjectAdapter(resourceGraph, resourceFactory, options, relationshipDataAdapter);
var resourceDataAdapter = new ResourceDataAdapter(resourceDefinitionAccessor, resourceObjectAdapter);

var atomicReferenceAdapter = new AtomicReferenceAdapter(resourceGraph, resourceFactory);
var atomicOperationResourceDataAdapter = new ResourceDataInOperationsRequestAdapter(resourceDefinitionAccessor, resourceObjectAdapter);

var atomicOperationObjectAdapter = new AtomicOperationObjectAdapter(options, atomicReferenceAdapter,
atomicOperationResourceDataAdapter, relationshipDataAdapter);

var resourceDocumentAdapter = new DocumentInResourceOrRelationshipRequestAdapter(options, resourceDataAdapter, relationshipDataAdapter);
var operationsDocumentAdapter = new DocumentInOperationsRequestAdapter(options, atomicOperationObjectAdapter);

DocumentAdapter = new DocumentAdapter(request, targetedFields, resourceDocumentAdapter, operationsDocumentAdapter);
}

protected abstract JsonApiRequest CreateJsonApiRequest(IResourceGraph resourceGraph);

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class ResourceA : Identifiable
{
[Attr]
public bool Attribute01 { get; set; }

[Attr]
public char Attribute02 { get; set; }

[Attr]
public ulong? Attribute03 { get; set; }

[Attr]
public decimal Attribute04 { get; set; }

[Attr]
public float? Attribute05 { get; set; }

[Attr]
public string Attribute06 { get; set; }

[Attr]
public DateTime? Attribute07 { get; set; }

[Attr]
public DateTimeOffset? Attribute08 { get; set; }

[Attr]
public TimeSpan? Attribute09 { get; set; }

[Attr]
public DayOfWeek Attribute10 { get; set; }

[HasOne]
public ResourceA Single1 { get; set; }

[HasOne]
public ResourceA Single2 { get; set; }

[HasOne]
public ResourceA Single3 { get; set; }

[HasOne]
public ResourceA Single4 { get; set; }

[HasOne]
public ResourceA Single5 { get; set; }

[HasMany]
public ISet<ResourceA> Multi1 { get; set; }

[HasMany]
public ISet<ResourceA> Multi2 { get; set; }

[HasMany]
public ISet<ResourceA> Multi3 { get; set; }

[HasMany]
public ISet<ResourceA> Multi4 { get; set; }

[HasMany]
public ISet<ResourceA> Multi5 { get; set; }
}
}
}
Loading