@@ -179,12 +179,7 @@ public function normalize(mixed $object, string $format = null, array $context =
179179 $ attributeValue = $ attribute === $ this ->classDiscriminatorResolver ?->getMappingForMappedObject($ object )?->getTypeProperty()
180180 ? $ this ->classDiscriminatorResolver ?->getTypeForMappedObject($ object )
181181 : $ this ->getAttributeValue ($ object , $ attribute , $ format , $ attributeContext );
182- } catch (UninitializedPropertyException $ e ) {
183- if ($ context [self ::SKIP_UNINITIALIZED_VALUES ] ?? $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ] ?? true ) {
184- continue ;
185- }
186- throw $ e ;
187- } catch (\Error $ e ) {
182+ } catch (UninitializedPropertyException |\Error $ e ) {
188183 if (($ context [self ::SKIP_UNINITIALIZED_VALUES ] ?? $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ] ?? true ) && $ this ->isUninitializedValueError ($ e )) {
189184 continue ;
190185 }
@@ -349,6 +344,10 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
349344 ? $ discriminatorMapping
350345 : $ this ->getAttributeValue ($ object , $ attribute , $ format , $ attributeContext );
351346 } catch (NoSuchPropertyException ) {
347+ } catch (UninitializedPropertyException |\Error $ e ) {
348+ if (!(($ context [self ::SKIP_UNINITIALIZED_VALUES ] ?? $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ] ?? true ) && $ this ->isUninitializedValueError ($ e ))) {
349+ throw $ e ;
350+ }
352351 }
353352 }
354353
@@ -742,9 +741,10 @@ private function getCacheKey(?string $format, array $context): bool|string
742741 * This error may occur when specific object normalizer implementation gets attribute value
743742 * by accessing a public uninitialized property or by calling a method accessing such property.
744743 */
745- private function isUninitializedValueError (\Error $ e ): bool
744+ private function isUninitializedValueError (\Error | UninitializedPropertyException $ e ): bool
746745 {
747- return str_starts_with ($ e ->getMessage (), 'Typed property ' )
746+ return $ e instanceof UninitializedPropertyException
747+ || str_starts_with ($ e ->getMessage (), 'Typed property ' )
748748 && str_ends_with ($ e ->getMessage (), 'must not be accessed before initialization ' );
749749 }
750750
0 commit comments