use Symfony\Component\Serializer\Exception\BadMethodCallException;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
+use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerInterface;
$serializer = $this->serializer;
$class = substr($class, 0, -2);
- return array_map(
- function ($data) use ($serializer, $class, $format, $context) {
- return $serializer->denormalize($data, $class, $format, $context);
- },
- $data
- );
+ $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
+ foreach ($data as $key => $value) {
+ if (null !== $builtinType && !call_user_func('is_'.$builtinType, $key)) {
+ throw new UnexpectedValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, gettype($key)));
+ }
+
+ $data[$key] = $serializer->denormalize($value, $class, $format, $context);
+ }
+
+ return $data;
}
/**