22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
5+ using JsonApiDotNetCore . Extensions ;
56using JsonApiDotNetCore . Internal ;
67using JsonApiDotNetCore . Internal . Generics ;
78using JsonApiDotNetCore . Models ;
@@ -15,14 +16,20 @@ namespace JsonApiDotNetCore.Serialization
1516 public class JsonApiDeSerializer : IJsonApiDeSerializer
1617 {
1718 private readonly IJsonApiContext _jsonApiContext ;
18- private readonly IGenericProcessorFactory _genericProcessorFactory ;
1919
20+ [ Obsolete (
21+ "The deserializer no longer depends on the IGenericProcessorFactory" ,
22+ error : false ) ]
2023 public JsonApiDeSerializer (
2124 IJsonApiContext jsonApiContext ,
2225 IGenericProcessorFactory genericProcessorFactory )
2326 {
2427 _jsonApiContext = jsonApiContext ;
25- _genericProcessorFactory = genericProcessorFactory ;
28+ }
29+
30+ public JsonApiDeSerializer ( IJsonApiContext jsonApiContext )
31+ {
32+ _jsonApiContext = jsonApiContext ;
2633 }
2734
2835 public object Deserialize ( string requestBody )
@@ -225,11 +232,6 @@ private object SetHasManyRelationship(object entity,
225232 ContextEntity contextEntity ,
226233 Dictionary < string , RelationshipData > relationships )
227234 {
228- var entityProperty = entityProperties . FirstOrDefault ( p => p . Name == attr . InternalRelationshipName ) ;
229-
230- if ( entityProperty == null )
231- throw new JsonApiException ( 400 , $ "{ contextEntity . EntityType . Name } does not contain an relationsip named { attr . InternalRelationshipName } ") ;
232-
233235 var relationshipName = attr . PublicRelationshipName ;
234236
235237 if ( relationships . TryGetValue ( relationshipName , out RelationshipData relationshipData ) )
@@ -238,11 +240,18 @@ private object SetHasManyRelationship(object entity,
238240
239241 if ( data == null ) return entity ;
240242
241- var genericProcessor = _genericProcessorFactory . GetProcessor < IGenericProcessor > ( typeof ( GenericProcessor < > ) , attr . Type ) ;
243+ var relationshipShells = relationshipData . ManyData . Select ( r =>
244+ {
245+ var instance = attr . Type . New < IIdentifiable > ( ) ;
246+ instance . StringId = r . Id ;
247+ return instance ;
248+ } ) ;
249+
250+ var convertedCollection = TypeHelper . ConvertCollection ( relationshipShells , attr . Type ) ;
242251
243- var ids = relationshipData . ManyData . Select ( r => r . Id ) ;
252+ attr . SetValue ( entity , convertedCollection ) ;
244253
245- genericProcessor . SetRelationships ( entity , attr , ids ) ;
254+ _jsonApiContext . HasManyRelationshipPointers . Add ( attr . Type , convertedCollection ) ;
246255 }
247256
248257 return entity ;
0 commit comments