-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Recently Added Valhalla Alternates Serialization #2811
Conversation
|
||
// for each route | ||
for (int i = 0; i < api.directions().routes_size(); ++i) { | ||
if (i == 1) { | ||
writer.start_array("alternates"); | ||
} | ||
|
||
// the main route | ||
// the route itself | ||
writer.start_object(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every route needs to be wrapped in an object {
we had only one for the outer object in the response but for each of the alternates we didnt add one. this lead to json that looked like:
{
"trip": .... main route here,
"alternates": [
"trip",
{guts of alternate here},
rapidjson::Document doc; | ||
doc.Parse(json); | ||
ASSERT_FALSE(doc.HasParseError()); | ||
ASSERT_TRUE(doc.HasMember("trip")); | ||
ASSERT_TRUE(doc.HasMember("alternates") == (num_alternates > 0)); | ||
if (num_alternates > 0) { | ||
for (const auto& alt : doc["alternates"].GetArray()) { | ||
ASSERT_TRUE(alt.HasMember("trip")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we actually check that the json isnt bunk
In adding #2734 we needed a way to represent alternate routes in the valhalla serializer. In the first iteration of that PR it was added while we were still using the old json serializer. Before I merged the PR though many other PRs made it into master which caused a huge merge parade. As a part of that merge process I needed to reconcile the new json serialization (using rapidjson) with the old code. I thought I had done that but infact I was wrong and there wasnt any test coverage of it. I've added test coverage in this pr and also fixed the serialization.