fix reflection type
This commit is contained in:
parent
3fe9802ead
commit
e437e0408e
@ -332,8 +332,14 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
||||
}
|
||||
} elseif ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
|
||||
$parameterData = $data[$key];
|
||||
if (null !== $constructorParameter->getClass()) {
|
||||
$parameterData = $this->serializer->deserialize($parameterData, $constructorParameter->getClass()->getName(), $format, $context);
|
||||
if (null !== $constructorParameter->getType()) {
|
||||
try {
|
||||
$parameterClass = $constructorParameter->getClass()->getName();
|
||||
} catch (\ReflectionException $e) {
|
||||
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $key), 0, $e);
|
||||
}
|
||||
|
||||
$parameterData = $this->serializer->deserialize($parameterData, $parameterClass, $format, $context);
|
||||
}
|
||||
|
||||
// Don't run set for a parameter passed to the constructor
|
||||
|
@ -180,6 +180,27 @@ class ObjectNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('rab', $obj->getInner()->bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Could not determine the class of the parameter "unknown".
|
||||
*/
|
||||
public function testConstructorWithUnknownObjectTypeHintDenormalize()
|
||||
{
|
||||
$data = array(
|
||||
'id' => 10,
|
||||
'unknown' => array(
|
||||
'foo' => 'oof',
|
||||
'bar' => 'rab',
|
||||
),
|
||||
);
|
||||
|
||||
$normalizer = new ObjectNormalizer();
|
||||
$serializer = new DenormalizerDecoratorSerializer($normalizer);
|
||||
$normalizer->setSerializer($serializer);
|
||||
|
||||
$normalizer->denormalize($data, DummyWithConstructorInexistingObject::class);
|
||||
}
|
||||
|
||||
public function testGroupsNormalize()
|
||||
{
|
||||
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
|
||||
@ -827,3 +848,10 @@ class DummyWithConstructorObject
|
||||
return $this->inner;
|
||||
}
|
||||
}
|
||||
|
||||
class DummyWithConstructorInexistingObject
|
||||
{
|
||||
public function __construct($id, Unknown $unknown)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user