1- using System . Text . Json ;
21using JetBrains . Annotations ;
32using JsonApiDotNetCore . Middleware ;
43using JsonApiDotNetCore . Resources . Annotations ;
@@ -13,9 +12,9 @@ public sealed class ResourceChangeTracker<TResource> : IResourceChangeTracker<TR
1312 private readonly IJsonApiRequest _request ;
1413 private readonly ITargetedFields _targetedFields ;
1514
16- private IDictionary < string , string > ? _initiallyStoredAttributeValues ;
17- private IDictionary < string , string > ? _requestAttributeValues ;
18- private IDictionary < string , string > ? _finallyStoredAttributeValues ;
15+ private IDictionary < string , object ? > ? _initiallyStoredAttributeValues ;
16+ private IDictionary < string , object ? > ? _requestAttributeValues ;
17+ private IDictionary < string , object ? > ? _finallyStoredAttributeValues ;
1918
2019 public ResourceChangeTracker ( IJsonApiRequest request , ITargetedFields targetedFields )
2120 {
@@ -50,15 +49,14 @@ public void SetFinallyStoredAttributeValues(TResource resource)
5049 _finallyStoredAttributeValues = CreateAttributeDictionary ( resource , _request . PrimaryResourceType ! . Attributes ) ;
5150 }
5251
53- private IDictionary < string , string > CreateAttributeDictionary ( TResource resource , IEnumerable < AttrAttribute > attributes )
52+ private IDictionary < string , object ? > CreateAttributeDictionary ( TResource resource , IEnumerable < AttrAttribute > attributes )
5453 {
55- var result = new Dictionary < string , string > ( ) ;
54+ var result = new Dictionary < string , object ? > ( ) ;
5655
5756 foreach ( AttrAttribute attribute in attributes )
5857 {
5958 object ? value = attribute . GetValue ( resource ) ;
60- string json = JsonSerializer . Serialize ( value ) ;
61- result . Add ( attribute . PublicName , json ) ;
59+ result . Add ( attribute . PublicName , value ) ;
6260 }
6361
6462 return result ;
@@ -71,21 +69,21 @@ public bool HasImplicitChanges()
7169 {
7270 foreach ( string key in _initiallyStoredAttributeValues . Keys )
7371 {
74- if ( _requestAttributeValues . TryGetValue ( key , out string ? requestValue ) )
72+ if ( _requestAttributeValues . TryGetValue ( key , out object ? requestValue ) )
7573 {
76- string actualValue = _finallyStoredAttributeValues [ key ] ;
74+ object ? actualValue = _finallyStoredAttributeValues [ key ] ;
7775
78- if ( requestValue != actualValue )
76+ if ( ! Equals ( requestValue , actualValue ) )
7977 {
8078 return true ;
8179 }
8280 }
8381 else
8482 {
85- string initiallyStoredValue = _initiallyStoredAttributeValues [ key ] ;
86- string finallyStoredValue = _finallyStoredAttributeValues [ key ] ;
83+ object ? initiallyStoredValue = _initiallyStoredAttributeValues [ key ] ;
84+ object ? finallyStoredValue = _finallyStoredAttributeValues [ key ] ;
8785
88- if ( initiallyStoredValue != finallyStoredValue )
86+ if ( ! Equals ( initiallyStoredValue , finallyStoredValue ) )
8987 {
9088 return true ;
9189 }
0 commit comments