/** * @param array $values * @param string $class * @param string $format * @param array $context * * @return array|object */ public function denormalize($values, $class, $format = null, array $context = array()) { if (!is_array($values)) { return $values; } $filtered = array_filter($values, function ($value) use($class, $format) { return $this->serializer->supportsDenormalization($value, $class, $format); }); if (count($filtered) !== count($values)) { throw new \InvalidArgumentException('Not all values within the array can be denormalized.'); } return array_map(function ($value) use($class, $format, $context) { return $this->serializer->denormalize($value, $class, $format, $context); }, $filtered); }
/** * {@inheritdoc} */ public function supportsDenormalization($data, $type, $format = null) { return substr($type, -2) === '[]' && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format); }