public function denormalize($data, $class, $format = null, array $context = array())
{
if (!isset($context['cache_key'])) {
$context['cache_key'] = $this->getCacheKey($format, $context);
}
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
$normalizedData = $this->prepareForDenormalization($data);
$extraAttributes = array();
$reflectionClass = new \ReflectionClass($class);
$object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes, $format);
foreach ($normalizedData as $attribute => $value) {
if ($this->nameConverter) {
$attribute = $this->nameConverter->denormalize($attribute);
}
if ($allowedAttributes !== false && !in_array($attribute, $allowedAttributes) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) {
if (isset($context['allow_extra_attributes']) && !$context['allow_extra_attributes']) {
$extraAttributes[] = $attribute;
}
continue;
}
$value = $this->validateAndDenormalize($class, $attribute, $value, $format, $context);
try {
$this->setAttributeValue($object, $attribute, $value, $format, $context);
} catch (InvalidArgumentException $e) {
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
}
}
if (!empty($extraAttributes)) {
throw new ExtraAttributesException($extraAttributes);
}
return $object;
}