Search code examples
phpxmlxsdjms-serializer

Unable to serialize empty array to empty XML element with JMS serializer


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.


Solution

  • 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