JMSSerializerBundle
JMSSerializerBundle copied to clipboard
The format_output option is not working ?
I wanted to remove the indentation from my XML output, but the format_output option doesn't seem to work. The other options seem to work well.
My config/packages/jms_serializer.yaml file :
jms_serializer:
visitors:
xml_serialization:
format_output: false
property_naming:
id: 'jms_serializer.identical_property_naming_strategy'
My jms bundle version :
jms/serializer:3.6.0
jms/serializer-bundle :3.5.0
Is that a bug or did I miss someting on the configuration documentation ?
can you please send a failing test case?
The class I want to serialize:
<?php
namespace App\DTO\Connect;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\XmlRoot("xml")
*/
class testOutputDTO {
/**
* @Serializer\XmlElement(cdata=false)
* @Serializer\Type("string")
*/
public $firstname;
/**
* @Serializer\XmlElement(cdata=false)
* @Serializer\Type("string")
*/
public $lastname;
/**
* @Serializer\XmlElement(cdata=false)
* @Serializer\Type("string")
*/
public $email;
public function hydrateDTO($firstname, $lastname, $email) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->email = $email;
return $this;
}
}
My test controller :
/**
* @Route("test-serialize", name="test_serialize")
*/
public function testSerialize(SerializerInterface $serializer){
$expeditionDTO = new testOutputDTO();
$expeditionDTO->hydrateDTO("John","Doe","[email protected]");
$xml = $serializer->serialize($expeditionDTO, 'xml');
dump($xml);
return new Response();
}
The dump output :
"""
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<firstname>John</firstname>
<lastname>Doe</lastname>
<email>[email protected]</email>
</xml>
"""
I hope that's enough, thanks.
Are you sure that you don't have in the packages dev folder another jms_serializer.yml with the settings to true?
In JMSSerializerExtension has line if (!empty($config['visitors']['xml_serialization']['format_output'])) { and if format_output is false, !empty return false, condition will not work, format_output will remain with the default true.