[go: up one dir, main page]

Menu

#1323 Required nillable fields missing when using std::optional instead of pointers

v1.0 (example)
open
nobody
None
5
2025-12-11
2025-12-11
No

When using (raw) pointers for required nillable fields <ns:tag xsi:nil="true"/> will be output if the value is a nullptr however when using $OPTIONAL = std::optional instead the field is omitted from the output entirely if the optional is empty.

e.g. for some type T with a required nillable field 'elem':

When using pointers soap_out_T() will contain:

if (!a->T::elem)
{
    if (soap_element_nil(soap, "ns:elem"))
        return soap->error;
}
else if (soap_out_PointerToElemT(soap, "ns:elem", -1, &a->T::elem, ""))
    return soap->error;

But when using std::optional it will just do:

if (soap_out_std__optionalTemplateOfElemT(soap, "ns:elem", -1, &a->T::elem, ""))
    return soap_error;

soap_out_std__optionalTemplateOfElemT() will call soap_element_null() if the optional is empty but this doesn't have the same behaviour as calling soap_element_nil() directly and will only output a nil="true" tag if SOAP_XML_NIL is also defined.
As the field is required shouldn't there be a check for the optional being empty and then call soap_element_nil() in that case?

Discussion


Log in to post a comment.