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

This forum deals with any kind of routing computation whether it is simple A:B-routing, calculation of isochrones, simple matrix computation or nearest search.
Post Reply
User avatar
Bernd Welter
Site Admin
Posts: 2825
Joined: Mon Apr 14, 2014 10:28 am
Contact:

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

Post 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()
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Maximilian Vogel
Posts: 20
Joined: Fri Dec 29, 2017 9:00 am

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

Post 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.
Maximilian Vogel
Developer
PTV Logistics
Post Reply