Skip to content
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

Merged
merged 4 commits into from
Jan 27, 2021

Conversation

kevinkreiser
Copy link
Member

@kevinkreiser kevinkreiser commented Jan 27, 2021

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.

gknisely
gknisely previously approved these changes Jan 27, 2021

// 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();
Copy link
Member Author

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},

Comment on lines +60 to +69
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"));
}
}
Copy link
Member Author

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

@kevinkreiser kevinkreiser merged commit 7659bbf into master Jan 27, 2021
@kevinkreiser kevinkreiser deleted the fix_alt_serialization branch January 5, 2022 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants