99using JsonApiDotNetCore . Services ;
1010using Newtonsoft . Json ;
1111using Newtonsoft . Json . Linq ;
12+ using JsonApiDotNetCore . Extensions ;
1213
1314namespace JsonApiDotNetCore . Serialization
1415{
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,10 +232,11 @@ private object SetHasManyRelationship(object entity,
225232 ContextEntity contextEntity ,
226233 Dictionary < string , RelationshipData > relationships )
227234 {
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);
229237
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}' ");
232240
233241 var relationshipName = attr . PublicRelationshipName ;
234242
@@ -238,11 +246,16 @@ private object SetHasManyRelationship(object entity,
238246
239247 if ( data == null ) return entity ;
240248
241- var genericProcessor = _genericProcessorFactory . GetProcessor < IGenericProcessor > ( typeof ( GenericProcessor < > ) , attr . Type ) ;
249+ var resourceRelationships = attr . Type . GetEmptyCollection < IIdentifiable > ( ) ;
242250
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+ } ) ;
244257
245- genericProcessor . SetRelationships ( entity , attr , ids ) ;
258+ attr . SetValue ( entity , relationshipShells ) ;
246259 }
247260
248261 return entity ;
0 commit comments