Open iamsophiesk opened 7 years ago
type="null"
means that your type is a "string" with value string(4) "null"
, not NULL
If you need to represent NULL
as attribute, it is not an easy thing. I suggest you to use an element... is a controversial topic https://stackoverflow.com/questions/774192/what-is-the-correct-way-to-represent-null-xml-elements
Thanks for the speedy response. This is all based on a separate system that expects the data in this format, and the client doesn't want to change it (until after we launch the product in ~3-6 months).
When you say "your type is a 'string' with value ...", I have in code:
/**
* The type of this value.
*
* @XmlAttribute
*/
private $type = 'null';
So would you expect it to have @Type("string")
in the annotation? Hm - not sure what I should change if anything?
@Type("string")
should work
Hmm, nope, I ended up with this:
<DateOfBirth xsi:nil="true"/>
<CreatedDate>
<type>null</type>
<date>/Date(1501683112000)/</date>
</CreatedDate>
Code:
/**
* The type of this value.
*
* @XmlAttribute
* @XmlElement(cdata=false)
* @Type("string")
*/
private $type = 'null';
/**
* The value of this date field.
*
* @var string
*
* @XmlValue
* @XmlElement(cdata=false)
*/
private $date;
I think I might just wait for the client to come back to me - it seems like I'm trying to ask the serializer to do something that it just doesn't want to do!
Hiya
I'm trying to build some XML that looks something like this:
Where the date of birth is a string or null. When I add
$contact->setSerializeNull(TRUE);
I get something like:The XML namespacing is undesirable; the CRM system I'm posting this data to cannot interpret this. I am also unable to change the
xsi:nil="true"
attribute in the DateOfBirth.I have set up a DoB class thus:
But this only works for dates where there is a value, eg:
Is there a way to force the
type="null"
attribute? Is there a way to remove the XML namespacing from all elements in the record?Or should I just revert to
SimpleXMLElement
again? Totally not what I want to do, but ...Thanks!