@@ -26,6 +26,7 @@ final class DefinitionProvider
2626 private PropertyTypeResolver $ propertyTypeResolver ;
2727 private bool $ serializePublicMethods ;
2828 private ConstructorResolver $ constructorResolver ;
29+ private bool $ serializeMapsAsObjects ;
2930
3031 public function __construct (
3132 ?DefaultCasterRepository $ defaultCasterRepository = null ,
@@ -34,6 +35,7 @@ public function __construct(
3435 ?PropertyTypeResolver $ propertyTypeResolver = null ,
3536 bool $ serializePublicMethods = true ,
3637 ?ConstructorResolver $ constructorResolver = null ,
38+ bool $ serializeMapsAsObjects = false ,
3739 )
3840 {
3941 $ this ->defaultCasters = $ defaultCasterRepository ?? DefaultCasterRepository::builtIn ();
@@ -42,6 +44,7 @@ public function __construct(
4244 $ this ->propertyTypeResolver = $ propertyTypeResolver ?? new NaivePropertyTypeResolver ();
4345 $ this ->serializePublicMethods = $ serializePublicMethods ;
4446 $ this ->constructorResolver = $ constructorResolver ?? new AttributeConstructorResolver ();
47+ $ this ->serializeMapsAsObjects = $ serializeMapsAsObjects ;
4548 }
4649
4750 /**
@@ -146,6 +149,7 @@ private function stringifyConstructor(ReflectionMethod $constructor): string
146149 public function provideSerializationDefinition (string $ className ): ClassSerializationDefinition
147150 {
148151 $ reflection = new ReflectionClass ($ className );
152+ $ constructor = $ this ->constructorResolver ->resolveConstructor ($ reflection );
149153 $ objectSettings = $ this ->resolveObjectSettings ($ reflection );
150154 $ classAttributes = $ reflection ->getAttributes ();
151155 $ properties = [];
@@ -173,7 +177,7 @@ public function provideSerializationDefinition(string $className): ClassSerializ
173177 PropertySerializationDefinition::TYPE_METHOD ,
174178 $ methodName ,
175179 $ this ->resolveSerializers ($ returnType , $ attributes ),
176- PropertyType:: fromReflectionType ( $ returnType ),
180+ $ this -> propertyTypeResolver -> typeFromMethod ( $ method ),
177181 $ returnType ->allowsNull (),
178182 $ this ->resolveKeys ($ key , $ attributes ),
179183 $ typeSpecifier ?->key,
@@ -204,7 +208,7 @@ public function provideSerializationDefinition(string $className): ClassSerializ
204208 PropertySerializationDefinition::TYPE_PROPERTY ,
205209 $ property ->getName (),
206210 $ serializers ,
207- PropertyType:: fromReflectionType ( $ propertyType ),
211+ $ this -> propertyTypeResolver -> typeFromProperty ( $ property , $ constructor ),
208212 $ propertyType ->allowsNull (),
209213 $ this ->resolveKeys ($ key , $ attributes ),
210214 $ typeSpecifier ?->key,
@@ -307,6 +311,11 @@ public function hasSerializerFor(string $name): bool
307311 return $ this ->defaultSerializers ->serializerForType ($ name ) !== null ;
308312 }
309313
314+ public function areMapsSerializedAsObjects (): bool
315+ {
316+ return $ this ->serializeMapsAsObjects ;
317+ }
318+
310319 /**
311320 * @param ReflectionAttribute[] $attributes
312321 *
0 commit comments