@@ -226,36 +226,42 @@ public function denormalize($data, $class, $format = null, array $context = [])
226
226
$ normalizedData = is_scalar ($ data ) ? [$ data ] : $ this ->prepareForDenormalization ($ data );
227
227
$ class = $ this ->getClassDiscriminatorResolvedClass ($ normalizedData , $ class );
228
228
}
229
+
229
230
$ resourceClass = $ this ->resourceClassResolver ->getResourceClass ($ objectToPopulate , $ class );
230
231
$ context ['api_denormalize ' ] = true ;
231
232
$ context ['resource_class ' ] = $ resourceClass ;
232
233
233
- if (null !== ($ inputClass = $ this ->getInputClass ($ resourceClass , $ context )) && null !== ($ dataTransformer = $ this ->getDataTransformer ($ data , $ resourceClass , $ context ))) {
234
- $ dataTransformerContext = $ context ;
234
+ if (null !== $ inputClass = $ this ->getInputClass ($ resourceClass , $ context )) {
235
+ if (null !== $ dataTransformer = $ this ->getDataTransformer ($ data , $ resourceClass , $ context )) {
236
+ $ dataTransformerContext = $ context ;
235
237
236
- unset($ context ['input ' ]);
237
- unset($ context ['resource_class ' ]);
238
+ unset($ context ['input ' ]);
239
+ unset($ context ['resource_class ' ]);
238
240
239
- if (!$ this ->serializer instanceof DenormalizerInterface) {
240
- throw new LogicException ('Cannot denormalize the input because the injected serializer is not a denormalizer ' );
241
- }
241
+ if (!$ this ->serializer instanceof DenormalizerInterface) {
242
+ throw new LogicException ('Cannot denormalize the input because the injected serializer is not a denormalizer ' );
243
+ }
242
244
243
- if ($ dataTransformer instanceof DataTransformerInitializerInterface) {
244
- $ context [AbstractObjectNormalizer::OBJECT_TO_POPULATE ] = $ dataTransformer ->initialize ($ inputClass , $ context );
245
- $ context [AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE ] = true ;
246
- }
245
+ if ($ dataTransformer instanceof DataTransformerInitializerInterface) {
246
+ $ context [AbstractObjectNormalizer::OBJECT_TO_POPULATE ] = $ dataTransformer ->initialize ($ inputClass , $ context );
247
+ $ context [AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE ] = true ;
248
+ }
247
249
248
- try {
249
- $ denormalizedInput = $ this ->serializer ->denormalize ($ data , $ inputClass , $ format , $ context );
250
- } catch (NotNormalizableValueException $ e ) {
251
- throw new UnexpectedValueException ('The input data is misformatted. ' , $ e ->getCode (), $ e );
252
- }
250
+ try {
251
+ $ denormalizedInput = $ this ->serializer ->denormalize ($ data , $ inputClass , $ format , $ context );
252
+ } catch (NotNormalizableValueException $ e ) {
253
+ throw new UnexpectedValueException ('The input data is misformatted. ' , $ e ->getCode (), $ e );
254
+ }
255
+
256
+ if (!\is_object ($ denormalizedInput )) {
257
+ throw new UnexpectedValueException ('Expected denormalized input to be an object. ' );
258
+ }
253
259
254
- if (!\is_object ($ denormalizedInput )) {
255
- throw new UnexpectedValueException ('Expected denormalized input to be an object. ' );
260
+ return $ dataTransformer ->transform ($ denormalizedInput , $ resourceClass , $ dataTransformerContext );
256
261
}
257
262
258
- return $ dataTransformer ->transform ($ denormalizedInput , $ resourceClass , $ dataTransformerContext );
263
+ $ resourceClass = $ inputClass ;
264
+ $ context ['resource_class ' ] = $ inputClass ;
259
265
}
260
266
261
267
$ supportsPlainIdentifiers = $ this ->supportsPlainIdentifiers ();
0 commit comments