2
2
using System . Collections . Generic ;
3
3
using System . Reflection ;
4
4
using System . Text . Json ;
5
- using System . Text . Json . Serialization ;
6
5
using JetBrains . Annotations ;
7
6
using JsonApiDotNetCore . Configuration ;
8
7
using JsonApiDotNetCore . Resources ;
@@ -15,7 +14,7 @@ namespace JsonApiDotNetCore.Serialization.JsonConverters
15
14
/// Converts <see cref="ResourceObject" /> to/from JSON.
16
15
/// </summary>
17
16
[ UsedImplicitly ( ImplicitUseKindFlags . InstantiatedNoFixedConstructorSignature ) ]
18
- public sealed class ResourceObjectConverter : JsonConverter < ResourceObject >
17
+ public sealed class ResourceObjectConverter : JsonObjectConverter < ResourceObject >
19
18
{
20
19
private static readonly JsonEncodedText TypeText = JsonEncodedText . Encode ( "type" ) ;
21
20
private static readonly JsonEncodedText IdText = JsonEncodedText . Encode ( "id" ) ;
@@ -72,7 +71,7 @@ public override ResourceObject Read(ref Utf8JsonReader reader, Type typeToConver
72
71
{
73
72
// Newtonsoft.Json used to auto-convert number to strings, while System.Text.Json does not. This is so likely
74
73
// to hit users during upgrade that we special-case for this and produce a helpful error message.
75
- var jsonElement = JsonConverterSupport . ReadSubTree < JsonElement > ( ref reader , options ) ;
74
+ var jsonElement = ReadSubTree < JsonElement > ( ref reader , options ) ;
76
75
throw new JsonException ( $ "Failed to convert ID '{ jsonElement } ' of type '{ jsonElement . ValueKind } ' to type 'String'.") ;
77
76
}
78
77
@@ -99,17 +98,17 @@ public override ResourceObject Read(ref Utf8JsonReader reader, Type typeToConver
99
98
}
100
99
case "relationships" :
101
100
{
102
- resourceObject . Relationships = JsonConverterSupport . ReadSubTree < IDictionary < string , RelationshipObject > > ( ref reader , options ) ;
101
+ resourceObject . Relationships = ReadSubTree < IDictionary < string , RelationshipObject > > ( ref reader , options ) ;
103
102
break ;
104
103
}
105
104
case "links" :
106
105
{
107
- resourceObject . Links = JsonConverterSupport . ReadSubTree < ResourceLinks > ( ref reader , options ) ;
106
+ resourceObject . Links = ReadSubTree < ResourceLinks > ( ref reader , options ) ;
108
107
break ;
109
108
}
110
109
case "meta" :
111
110
{
112
- resourceObject . Meta = JsonConverterSupport . ReadSubTree < IDictionary < string , object > > ( ref reader , options ) ;
111
+ resourceObject . Meta = ReadSubTree < IDictionary < string , object > > ( ref reader , options ) ;
113
112
break ;
114
113
}
115
114
default :
@@ -124,7 +123,7 @@ public override ResourceObject Read(ref Utf8JsonReader reader, Type typeToConver
124
123
}
125
124
}
126
125
127
- throw JsonConverterSupport . GetEndOfStreamError ( ) ;
126
+ throw GetEndOfStreamError ( ) ;
128
127
}
129
128
130
129
private static string TryPeekType ( ref Utf8JsonReader reader )
@@ -196,7 +195,7 @@ private static IDictionary<string, object> ReadAttributes(ref Utf8JsonReader rea
196
195
// Inside a JsonConverter there is no way to know where in the JSON object tree we are. And the serializer
197
196
// is unable to provide the correct position either. So we avoid an exception and postpone producing an error
198
197
// response to the post-processing phase, by setting a sentinel value.
199
- var jsonElement = JsonConverterSupport . ReadSubTree < JsonElement > ( ref reader , options ) ;
198
+ var jsonElement = ReadSubTree < JsonElement > ( ref reader , options ) ;
200
199
201
200
attributeValue = new JsonInvalidAttributeInfo ( attributeName , property . PropertyType , jsonElement . ToString ( ) ,
202
201
jsonElement . ValueKind ) ;
@@ -215,7 +214,7 @@ private static IDictionary<string, object> ReadAttributes(ref Utf8JsonReader rea
215
214
}
216
215
}
217
216
218
- throw JsonConverterSupport . GetEndOfStreamError ( ) ;
217
+ throw GetEndOfStreamError ( ) ;
219
218
}
220
219
221
220
/// <summary>
@@ -240,25 +239,25 @@ public override void Write(Utf8JsonWriter writer, ResourceObject value, JsonSeri
240
239
if ( ! value . Attributes . IsNullOrEmpty ( ) )
241
240
{
242
241
writer . WritePropertyName ( AttributesText ) ;
243
- JsonConverterSupport . WriteSubTree ( writer , value . Attributes , options ) ;
242
+ WriteSubTree ( writer , value . Attributes , options ) ;
244
243
}
245
244
246
245
if ( ! value . Relationships . IsNullOrEmpty ( ) )
247
246
{
248
247
writer . WritePropertyName ( RelationshipsText ) ;
249
- JsonConverterSupport . WriteSubTree ( writer , value . Relationships , options ) ;
248
+ WriteSubTree ( writer , value . Relationships , options ) ;
250
249
}
251
250
252
251
if ( value . Links != null && value . Links . HasValue ( ) )
253
252
{
254
253
writer . WritePropertyName ( LinksText ) ;
255
- JsonConverterSupport . WriteSubTree ( writer , value . Links , options ) ;
254
+ WriteSubTree ( writer , value . Links , options ) ;
256
255
}
257
256
258
257
if ( ! value . Meta . IsNullOrEmpty ( ) )
259
258
{
260
259
writer . WritePropertyName ( MetaText ) ;
261
- JsonConverterSupport . WriteSubTree ( writer , value . Meta , options ) ;
260
+ WriteSubTree ( writer , value . Meta , options ) ;
262
261
}
263
262
264
263
writer . WriteEndObject ( ) ;
0 commit comments