@@ -58,7 +58,7 @@ public function supportsNormalization($data, $format = null)
58
58
public function normalize ($ object , $ format = null , array $ context = [])
59
59
{
60
60
if (!isset ($ context ['cache_key ' ])) {
61
- $ context ['cache_key ' ] = $ this ->getAttributeCacheKey ($ format , $ context );
61
+ $ context ['cache_key ' ] = $ this ->getCacheKey ($ format , $ context );
62
62
}
63
63
64
64
if ($ this ->isCircularReference ($ object , $ context )) {
@@ -94,7 +94,7 @@ public function normalize($object, $format = null, array $context = [])
94
94
throw new LogicException (sprintf ('Cannot normalize attribute "%s" because the injected serializer is not a normalizer ' , $ attribute ));
95
95
}
96
96
97
- $ data = $ this ->updateData ($ data , $ attribute , $ this ->serializer ->normalize ($ attributeValue , $ format , $ this ->createChildContext ($ context , $ attribute )));
97
+ $ data = $ this ->updateData ($ data , $ attribute , $ this ->serializer ->normalize ($ attributeValue , $ format , $ this ->createChildContext ($ context , $ attribute, $ format )));
98
98
}
99
99
100
100
return $ data ;
@@ -174,7 +174,7 @@ public function supportsDenormalization($data, $type, $format = null)
174
174
public function denormalize ($ data , $ class , $ format = null , array $ context = [])
175
175
{
176
176
if (!isset ($ context ['cache_key ' ])) {
177
- $ context ['cache_key ' ] = $ this ->getAttributeCacheKey ($ format , $ context );
177
+ $ context ['cache_key ' ] = $ this ->getCacheKey ($ format , $ context );
178
178
}
179
179
180
180
$ allowedAttributes = $ this ->getAllowedAttributes ($ class , $ context , true );
@@ -274,7 +274,7 @@ private function validateAndDenormalize($currentClass, $attribute, $data, $forma
274
274
throw new LogicException (sprintf ('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer ' , $ attribute , $ class ));
275
275
}
276
276
277
- $ childContext = $ this ->createChildContext ($ context , $ attribute );
277
+ $ childContext = $ this ->createChildContext ($ context , $ attribute, $ format );
278
278
if ($ this ->serializer ->supportsDenormalization ($ data , $ class , $ format , $ childContext )) {
279
279
return $ this ->serializer ->denormalize ($ data , $ class , $ format , $ childContext );
280
280
}
@@ -377,11 +377,18 @@ private function isMaxDepthReached(array $attributesMetadata, $class, $attribute
377
377
*
378
378
* {@inheritdoc}
379
379
*/
380
- protected function createChildContext (array $ parentContext , $ attribute )
380
+ protected function createChildContext (array $ parentContext , $ attribute/*, string $format = null */ )
381
381
{
382
- $ context = parent ::createChildContext ($ parentContext , $ attribute );
382
+ if (\func_num_args () >= 3 ) {
383
+ $ format = \func_get_arg (2 );
384
+ } else {
385
+ // will be deprecated in version 4
386
+ $ format = null ;
387
+ }
388
+
389
+ $ context = parent ::createChildContext ($ parentContext , $ attribute , $ format );
383
390
// format is already included in the cache_key of the parent.
384
- $ context ['cache_key ' ] = $ this ->getAttributeCacheKey ( '' , $ context );
391
+ $ context ['cache_key ' ] = $ this ->getCacheKey ( $ format , $ context );
385
392
386
393
return $ context ;
387
394
}
@@ -396,8 +403,9 @@ protected function createChildContext(array $parentContext, $attribute)
396
403
*
397
404
* @return bool|string
398
405
*/
399
- private function getAttributeCacheKey ($ format , array $ context )
406
+ private function getCacheKey ($ format , array $ context )
400
407
{
408
+ unset($ context ['cache_key ' ]); // avoid artificially different keys
401
409
try {
402
410
return md5 ($ format .serialize ([
403
411
'context ' => $ context ,
0 commit comments