Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mapbox welcomes participation and contributions from everyone.

### main
- Added roundtrip of unrecognized JSON properties [#1394](https://github.com/mapbox/mapbox-java/pull/1394)

### v6.4.1 - April 22, 2022
- Added correct escaping for `<white space>&<white space>` pattern in query parameters for `RouteOptions#toUrl`. [#1410](https://github.com/mapbox/mapbox-java/pull/1410).
Expand Down
5 changes: 3 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {

version = [
autoValue : '1.7',
autoValueGson : '0.8.0',
autoValueGson : '0.0.1',
junit : '4.12',
annotation : '1.0.0',
gson : '2.8.6',
Expand Down Expand Up @@ -31,7 +31,8 @@ ext {

dependenciesList = [
autoValue : "com.google.auto.value:auto-value:${version.autoValue}",
autoValueGson : "com.ryanharter.auto.value:auto-value-gson:${version.autoValueGson}",
autoValueGson : "com.mapbox.mapboxsdk:auto-value-gson:${version.autoValueGson}",
autoValueGsonRuntime: "com.mapbox.mapboxsdk:auto-value-gson-runtime:${version.autoValueGson}",
junit : "junit:junit:${version.junit}",
supportAnnotation : "androidx.annotation:annotation:${version.annotation}",
gson : "com.google.code.gson:gson:${version.gson}",
Expand Down
1 change: 1 addition & 0 deletions services-directions-models/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
// AutoValue
compileOnly dependenciesList.autoValue
compileOnly dependenciesList.autoValueGson
implementation dependenciesList.autoValueGsonRuntime
annotationProcessor(dependenciesList.autoValueGson)

// Test Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mapbox.api.directions.v5;

import com.google.gson.TypeAdapterFactory;
import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;
import com.mapbox.auto.value.gson.GsonTypeAdapterFactory;

/**
* Required so that AutoValue can generate specific type adapters when needed inside the direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static Admin fromJson(String json) {
* This builder can be used to set the values describing the {@link Admin}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* The 2 character ISO 3166-1 alpha-2 code that applies to a country boundary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public int compareTo(BannerComponents bannerComponents) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* A snippet of the full {@link BannerText#text()} which can be used for visually altering parts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static BannerInstructions fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Distance in meters from the beginning of the step at which the visual instruction should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static BannerText fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Plain text with all the {@link BannerComponents} text combined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static BannerView fromJson(String json) {
* @since 5.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Plain text with all the {@link BannerComponents} text combined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* and a {@link #degrees()} which is the range of degrees by which the angle can deviate.
*/
@AutoValue
public abstract class Bearing {
public abstract class Bearing extends DirectionsJsonObject {
Comment thread
vadzim-vys marked this conversation as resolved.

/**
* Build a new instance of this builder.
Expand Down Expand Up @@ -54,7 +54,7 @@ public static Bearing.Builder builder() {
* This builder can be used to set the values describing the {@link Bearing}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Clockwise value from true north between 0 and 360.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Closure fromJson(String json) {
* This builder can be used to set the values describing the {@link Closure}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Closure's geometry index start point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Congestion fromJson(String json) {
* This builder can be used to set the values describing the {@link Congestion}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Quantitative descriptor of congestion. 0 to 100.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @since 3.0.0
*/
@AutoValue
public abstract class DirectionsError implements Serializable {
public abstract class DirectionsError extends DirectionsJsonObject implements Serializable {

/**
* Create a new instance of this class by using the {@link Builder} class.
Expand Down Expand Up @@ -82,7 +82,7 @@ public static TypeAdapter<DirectionsError> typeAdapter(Gson gson) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* String indicating the state of the response. This is a separate code than the HTTP status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.gson.GsonBuilder;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.PointAsCoordinatesTypeAdapter;
import com.mapbox.auto.value.gson.SerializableJsonElement;
import com.mapbox.auto.value.gson.UnrecognizedJsonProperties;

import java.io.Serializable;
import java.util.Map;

/**
* Provides a base class for Directions model classes.
*
* @since 3.4.0
*/
public class DirectionsJsonObject implements Serializable {
public abstract class DirectionsJsonObject implements Serializable {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change (not sure how impactful it would actually be in practice). Could we make the methods return empty and implement downstream, how would it look like?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AutoValue won't generate fields for not abstract methods

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a few possible solutions right now.

Do breaking change

Maybe we can make ourself believe that it's not really a breaking change using following arguments: it more like a fix of a bug, nobody should have created an instance of DirectionsJsonObject, it doesn't make any sense to create an instance of DirectionsJsonObject. But abstract do really changes API.

Workaround

I can create an abstract class BaseDirectionsJsonObject which is going to be a parent of DirectionsJsonObject and move unrecognised filed there. I find this solution ugly but it won't break API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need to decide if somebody could be affected by not being able to instantiate DirectionsJsonObject. If we're sure that we will affect nobody, and even if we will we're ready to reply in their issues on github, then I let's break the rule.
If we don't feel confident, let's workaround

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel confident. I can't imaging a case when somebody instantiate DirectionsJsonObject but if somebody does it, I'd like to learn their case when they open an issue on our github 🙂
@LukasPaczos , @RingerJK , what do you think about it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VysotskiVadim I agree. There's no practical reason to extend the DirectionsJsonObject for developers, I think we can break here. Let's clearly state this in the changelog and go from there.


/**
* This takes the currently defined values found inside this instance and converts it to a json
Expand All @@ -27,4 +32,13 @@ public String toJson() {
gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter());
return gson.create().toJson(this);
}

@Nullable
@UnrecognizedJsonProperties
abstract Map<String, SerializableJsonElement> unrecognized();

abstract static class Builder<T extends Builder> {
@NonNull
abstract T unrecognized(Map<String, SerializableJsonElement> value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public DirectionsResponse updateWithRequestData(@NonNull RouteOptions routeOptio
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* String indicating the state of the response. This is a separate code than the HTTP status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public static DirectionsRoute fromJson(
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* The distance traveled from origin to destination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static DirectionsWaypoint fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Provides the way name which the waypoint's coordinate is snapped to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* consider using raw {@link RouteOptions#exclude()} directly.
*/
@AutoValue
public abstract class Exclude {
public abstract class Exclude extends DirectionsJsonObject {

/**
* Build a new instance of {@link Exclude}. Nothing is excluded by default.
Expand Down Expand Up @@ -66,7 +66,7 @@ public static Builder builder() {
* Use this builder to build an {@link Exclude} object.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Exclude certain road types from routing. The default is to not exclude anything from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static ExperimentalWaypointMetadata fromJson(String json) {
* This builder can be used to set the values describing the {@link ExperimentalWaypointMetadata}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Object representing experimental value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public static Incident fromJson(String json) {
* This builder can be used to set the values describing the {@link Incident}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Unique identifier for incident. It might be the only one <b>non-null</b> filed which meant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static IntersectionLanes fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Provide a boolean value you can use to determine if the given lane is valid for the user to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static LegAnnotation fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* The distance, in meters, between each pair of coordinates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public static LegStep fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* The distance traveled from the maneuver to the next {@link LegStep}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static MapboxShield fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Base url to query the styles endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static MapboxStreetsV8 fromJson(String json) {
* This builder can be used to set the values describing the {@link MapboxStreetsV8}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Class of the road exiting the intersection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static MaxSpeed fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Number indicating the posted speed limit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Metadata fromJson(String json) {
* This builder can be used to set the values describing the {@link Metadata}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Map indicating the key/value pairs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static RestStop fromJson(String json) {
* This builder can be used to set the values describing the {@link RestStop}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* The type of rest stop, either `rest_area` (includes parking only) or `service_area`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static RouteLeg fromJson(String json) {
* @since 3.0.0
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* A list of silent waypoints which were used to request a route.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public abstract class RouteOptions extends DirectionsJsonObject {

private static final String UTF_8 = "UTF-8";
private static final String ACCESS_TOKEN_URL_PARAM_NAME = "access_token";

/**
* Build a new instance of {@link RouteOptions} and sets default values for:
Expand Down Expand Up @@ -889,6 +890,9 @@ public static RouteOptions fromUrl(@NonNull URL url) {
int idx = query.indexOf("=");
String property = URLDecoder.decode(query.substring(0, idx), UTF_8);
String value = URLDecoder.decode(query.substring(idx + 1), UTF_8);
if (property.equals(ACCESS_TOKEN_URL_PARAM_NAME)) {
continue;
}
Comment on lines +893 to +895
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that covers this already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I added this line because one of tests failed


boolean isExperimental = false;
for (int i = 0; i < Experimental.experimentalParameters.length; i++) {
Expand Down Expand Up @@ -937,7 +941,7 @@ public URL toUrl(@NonNull String accessToken) {
.append(String.format("/%s", user()))
.append(String.format("/%s", profile()))
.append(String.format("/%s", coordinates()))
.append(String.format("?access_token=%s", accessToken))
.append(String.format("?%s=%s", ACCESS_TOKEN_URL_PARAM_NAME, accessToken))
.append(String.format("&geometries=%s", geometries()));

if (alternatives() != null) {
Expand Down Expand Up @@ -1134,7 +1138,7 @@ private static RouteOptions fromJsonString(@NonNull String json) {
* This builder can be used to set the values describing the {@link RouteOptions}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Base URL for the request.
Expand Down Expand Up @@ -2191,7 +2195,7 @@ public static Experimental fromJson(String json) {
* This builder can be used to set the values describing the {@link Experimental}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Object representing experimental value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ShieldSprite.
*/
@AutoValue
public abstract class ShieldSprite implements Serializable {
public abstract class ShieldSprite extends DirectionsJsonObject implements Serializable {

/**
* Create a new instance of this class by using the {@link ShieldSprite.Builder} class.
Expand Down Expand Up @@ -59,7 +59,7 @@ public static TypeAdapter<ShieldSprite> typeAdapter(Gson gson) {
* This builder can be used to set the values describing the {@link ShieldSprite}.
*/
@AutoValue.Builder
public abstract static class Builder {
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {

/**
* Shield sprite's name.
Expand Down
Loading