-
Notifications
You must be signed in to change notification settings - Fork 117
Bearing formatting fix #1121
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
Bearing formatting fix #1121
Conversation
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Show resolved
Hide resolved
| protected void writePoint(JsonWriter out, Point value) throws IOException { | ||
| writePointList(out, value.coordinates()); | ||
| protected void writePoint(JsonWriter out, Point point) throws IOException { | ||
| if (point == null) { |
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.
We are now choosing to ignore nulls, while we should actually be able to support them when serializing and deserializing Lists in the BaseCoordinatesTypeAdapter. I think we'll need to refactor both read and write methods.
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.
@LukasPaczos what logic should writePoint has in case of null Point?
also readPoint always returns non null Point or throws an exception.
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.
also readPoint always returns non null Point or throws an exception
That's what we'd need to refactor. Could we use JsonToken.NULL or a similar construct?
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.
Is this because before null wasn't an option when reach serialization / deserialization and now it is? I believe the problem is that before we were always dealing with Strings and not anymore 🤔 How serialization / deserialization was working before?
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.
@Guardiola31337 @LukasPaczos I think it's only because of waypointTargetsList() in RouteOptions.
Previously waypointTargets were stored as a String, so PointAsCoordinatesTypeAdapter was not used. But now they are a List<Point>, so PointAsCoordinatesTypeAdapter calls BaseCoordinatesTypeAdapter.writePoint().
It is possible to store nulls in waypointTargetsList, so we need to check for a null inside writePoint() method
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.
@korshaknn could we add some tests in RouteOptions verifying that the serialization / deserialization works 👌 (toJson / fromJson)?
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.
That's right @korshaknn, but we still need to serialize and deserialize this null, not skip it. I think the inconsistency will be caught with a test that @Guardiola31337 suggested.
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.
@LukasPaczos how that null Point should be serialized?
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.
how that
nullPoint should be serialized?
Probably "" (empty)? Could we run a quick test of toJson / fromJson before and after #1118 to check how was working, compare and do the same?
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.
Empty string sounds correct.
Guardiola31337
left a comment
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.
Apart from the comments below, when debugging this PR I also noticed that in DirectionsResponseFactory#generateRouteOptions we're using the deprecated annotations API instead of annotationsList 👀
Line 62 in 123e7cd
| .annotations(mapboxDirections.annotation()) |
| protected void writePoint(JsonWriter out, Point value) throws IOException { | ||
| writePointList(out, value.coordinates()); | ||
| protected void writePoint(JsonWriter out, Point point) throws IOException { | ||
| if (point == null) { |
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.
Is this because before null wasn't an option when reach serialization / deserialization and now it is? I believe the problem is that before we were always dealing with Strings and not anymore 🤔 How serialization / deserialization was working before?
| .bearings(bearings) | ||
| .accessToken(ACCESS_TOKEN) | ||
| .build(); | ||
| assertEquals(";;45,90;2,90;", |
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.
Debugging this PR I found that ParseUtils#parseToListOfListOfDoubles in this concrete example is not working as expected
@Test
public void checksParseToListOfListOfDoublesEmptyTrailing() {
List<List<Double>> bearings = ParseUtils.parseToListOfListOfDoubles(";;45,90;2,90;");
assertEquals(5, bearings.size());
}It should return a list of 5 elements and it's returning a list of 4 because of not splitting with trailing empty strings
Line 141 in 123e7cd
| String[] pairs = original.split(SEMICOLON); |
After changing to original.split(SEMICOLON, -1); other tests start failing. We should revisit the empty trailing scenarios for other fields too.
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.
tested it with @kmadsen , @Guardiola31337 you are right, bearing string should HAVE trailing ; if we pass null bearings.
I'll fix logic and tests
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.
@korshaknn is ";;45,90;2,90;" and ";;45,90;2,90" going to be equal in this case? I think it shouldn't be. We should take the strategy that Directions API uses:
- what happens if we pass
"45,90;"as the request parameter? Is it considered as 2 values (1 empty)? - what happens if we pass
"45,90;;"as the request parameter? Is it considered as 3 values (2 empty)?
If yes, we shouldn't trim the trailing empty string.
/cc @danpaz
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.
Oh, looks like we commented at the same time @korshaknn :) Thanks for verifying!
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.
@LukasPaczos
";;45,90;2,90;" will be valid for 5 coordinates
";;45,90;2,90" will be valid for 4 coordinates
|
@LukasPaczos @Guardiola31337 I decided to return old logic and use String to store to get |
|
The only concern I have is that if the end-users (and our SDKs) are going to rely on the Did you run into any issues when trying to serialize/deserialize nulls? |
|
@LukasPaczos no, I haven't had any issues with serialization/deserialization. |
The question is whether we can hopefully skip one of those steps and optimize the process. If you had no issues with serialization, could we try it? |
|
@LukasPaczos so I think it's better to store |
LukasPaczos
left a comment
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.
Alright, let's just try it out in this case. We can continue iterating if needed.
Is this needed? Can't those be serialized / deserialized equally? Would that help solving @LukasPaczos's concern? |
|
@Guardiola31337 it was serialized in a different way before refactoring. or maybe serialization/deserialization of |
These are valid questions 👍
That's a great question 🤔 Events maybe? It'd be great to find out testing downstream in the Navigation SDK and 👀 if everything is working 👌 or if there are any 💥 We can do that in a separate PR, so feel free to merge here 🚀 |
removed
bearingvalidation logic fromMapboxDirectionsnow both
RouteOptionsandMapboxDirectionsuseFormatUtils.formatBearings()to build a valid string from a list of bearingscloses #1120