I am assembling an XML file based on an XSD that requires an XML container element to be present, even if it is empty.
When I try to serialize an empty array, using JMS serializer, with configuration that works if the array is not empty, I get no element at all.
Can I resolve this by configuration or will I have to implement my own event handler?
Thanks in advance.
I did some digging and it turned out that there is an undocumented option that can be specified on xml_list
, called skip_when_empty
.
Support for the above mentioned property was also implemented in xsd2php with the following PR that was merged into master a few days ago: https://github.com/goetas-webservices/xsd2php/pull/27
Try this:
$serializer = JMS\SerializerBuilder::create();
$context = JMS\SerializationContext::create()->setSerializeNull(true);
$serializedString = $serializer->serialize($data, 'xml', $context);
here setSerializeNull(true)
will force property/properties to serialize even if it's null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With