Page 1 of 1

Zero-length array missing (e.g. toll summary)

Posted: Thu May 08, 2025 7:21 am
by Bernd Welter
Hi there,

one of our users just mentioned this effect I wasn't aware of. Could DEV please comment on this? Is this a bug?

The user works with xRoute2 and calculates toll. In the response he deals with the com.ptvgroup.xserver.xroute.TollSummary which is documented to return an array called costs with a length of 0 or more
TollSummary.png
Now under certain plausible conditions there might be no contribution of toll in any of the used countries and he would expect some

Code: Select all

"toll":
{
   "summary":
   {
      "costs":[],
      "countries":[]
   }
}
Instead he get's

Code: Select all

"toll": 
{
    "summary": {}
},
So neither "costs" nor "countries" appears at all.

Is this a bug? Philosophy? Art?
I think we use "0+ length" arrays at various elements - is this something we should change / handle in a different way?

Bernd

PS: in my own test applications I'd give the condition "there's no contribution" a dedicated treatment anyways such as

Code: Select all

if ((element != null) %% (element.Length>0))
{
// contribution case
}
else
{
// no contribution case
}
or with my quite usual style of filling data grids through C# I can apply

Code: Select all

dataGrid.DataSource = toll?.summary?.costs.Select(c => ...).ToArray()

Re: Zero-length array missing (e.g. toll summary)

Posted: Thu May 08, 2025 8:11 am
by Maximilian Vogel
This behaviour is in fact documented in the technical concept on requests and responses under the paragraph "Response structure":
Noteworthy about result lists: Empty result lists are omitted from the response. Depending on the used client technology you might have to check if a list exists before iterating over it.