9
9
using JsonApiDotNetCore . Services ;
10
10
using Newtonsoft . Json ;
11
11
using Newtonsoft . Json . Linq ;
12
+ using JsonApiDotNetCore . Extensions ;
12
13
13
14
namespace JsonApiDotNetCore . Serialization
14
15
{
15
16
public class JsonApiDeSerializer : IJsonApiDeSerializer
16
17
{
17
18
private readonly IJsonApiContext _jsonApiContext ;
18
- private readonly IGenericProcessorFactory _genericProcessorFactory ;
19
19
20
+ [ Obsolete (
21
+ "The deserializer no longer depends on the IGenericProcessorFactory" ,
22
+ error : false ) ]
20
23
public JsonApiDeSerializer (
21
24
IJsonApiContext jsonApiContext ,
22
25
IGenericProcessorFactory genericProcessorFactory )
23
26
{
24
27
_jsonApiContext = jsonApiContext ;
25
- _genericProcessorFactory = genericProcessorFactory ;
28
+ }
29
+
30
+ public JsonApiDeSerializer ( IJsonApiContext jsonApiContext )
31
+ {
32
+ _jsonApiContext = jsonApiContext ;
26
33
}
27
34
28
35
public object Deserialize ( string requestBody )
@@ -225,10 +232,11 @@ private object SetHasManyRelationship(object entity,
225
232
ContextEntity contextEntity ,
226
233
Dictionary < string , RelationshipData > relationships )
227
234
{
228
- var entityProperty = entityProperties . FirstOrDefault ( p => p . Name == attr . InternalRelationshipName ) ;
235
+ // TODO: is this necessary? if not, remove
236
+ // var entityProperty = entityProperties.FirstOrDefault(p => p.Name == attr.InternalRelationshipName);
229
237
230
- if ( entityProperty == null )
231
- throw new JsonApiException ( 400 , $ "{ contextEntity . EntityType . Name } does not contain an relationsip named { attr . InternalRelationshipName } ") ;
238
+ // if (entityProperty == null)
239
+ // throw new JsonApiException(400, $"{contextEntity.EntityType.Name} does not contain a relationsip named ' {attr.InternalRelationshipName}' ");
232
240
233
241
var relationshipName = attr . PublicRelationshipName ;
234
242
@@ -238,11 +246,16 @@ private object SetHasManyRelationship(object entity,
238
246
239
247
if ( data == null ) return entity ;
240
248
241
- var genericProcessor = _genericProcessorFactory . GetProcessor < IGenericProcessor > ( typeof ( GenericProcessor < > ) , attr . Type ) ;
249
+ var resourceRelationships = attr . Type . GetEmptyCollection < IIdentifiable > ( ) ;
242
250
243
- var ids = relationshipData . ManyData . Select ( r => r . Id ) ;
251
+ var relationshipShells = relationshipData . ManyData . Select ( r =>
252
+ {
253
+ var instance = attr . Type . New < IIdentifiable > ( ) ;
254
+ instance . StringId = r . Id ;
255
+ return instance ;
256
+ } ) ;
244
257
245
- genericProcessor . SetRelationships ( entity , attr , ids ) ;
258
+ attr . SetValue ( entity , relationshipShells ) ;
246
259
}
247
260
248
261
return entity ;
0 commit comments