[Serializer] Inlined back the logic from isStructuredType and removed the method
This commit is contained in:
parent
3ecc9602e4
commit
4104c7b073
@ -25,9 +25,6 @@ class JsonEncoder extends AbstractEncoder implements DecoderInterface
|
||||
*/
|
||||
public function encode($data, $format)
|
||||
{
|
||||
if ($this->serializer->isStructuredType($data)) {
|
||||
$data = $this->serializer->normalize($data, $format);
|
||||
}
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class XmlEncoder extends AbstractEncoder implements DecoderInterface
|
||||
$this->dom = new \DOMDocument();
|
||||
$this->format = $format;
|
||||
|
||||
if ($this->serializer->isStructuredType($data)) {
|
||||
if (null !== $data && !is_scalar($data)) {
|
||||
$root = $this->dom->createElement($this->rootNodeName);
|
||||
$this->dom->appendChild($root);
|
||||
$this->buildXml($root, $data);
|
||||
@ -248,8 +248,10 @@ class XmlEncoder extends AbstractEncoder implements DecoderInterface
|
||||
}
|
||||
if (is_object($data)) {
|
||||
$data = $this->serializer->normalizeObject($data, $this->format);
|
||||
if (!$this->serializer->isStructuredType($data)) {
|
||||
// top level data object is normalized into a scalar
|
||||
if (null !== $data && !is_scalar($data)) {
|
||||
return $this->buildXml($parentNode, $data);
|
||||
}
|
||||
// top level data object was normalized into a scalar
|
||||
if (!$parentNode->parentNode->parentNode) {
|
||||
$root = $parentNode->parentNode;
|
||||
$root->removeChild($parentNode);
|
||||
@ -257,8 +259,6 @@ class XmlEncoder extends AbstractEncoder implements DecoderInterface
|
||||
}
|
||||
return $this->appendNode($parentNode, $data, 'data');
|
||||
}
|
||||
return $this->buildXml($parentNode, $data);
|
||||
}
|
||||
throw new \UnexpectedValueException('An unexpected value could not be serialized: '.var_export($data, true));
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
||||
|
||||
if (null === $propertyMap || isset($propertyMap[$attributeName])) {
|
||||
$attributeValue = $method->invoke($object);
|
||||
if ($this->serializer->isStructuredType($attributeValue)) {
|
||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||
$attributeValue = $this->serializer->normalize($attributeValue, $format);
|
||||
}
|
||||
|
||||
|
@ -34,15 +34,6 @@ class Serializer implements SerializerInterface
|
||||
protected $normalizerCache = array();
|
||||
protected $denormalizerCache = array();
|
||||
|
||||
/**
|
||||
* @param mixed $value value to test
|
||||
* @return Boolean whether the type is a structured type (array + objects)
|
||||
*/
|
||||
public function isStructuredType($value)
|
||||
{
|
||||
return null !== $value && !is_scalar($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -104,7 +95,7 @@ class Serializer implements SerializerInterface
|
||||
*/
|
||||
public function normalize($data, $format = null)
|
||||
{
|
||||
if (!$this->isStructuredType($data)) {
|
||||
if (null === $value || is_scalar($value)) {
|
||||
return $data;
|
||||
}
|
||||
if ($data instanceof Traversable) {
|
||||
|
Reference in New Issue
Block a user