1414import com .mapbox .api .directions .v5 .utils .FormatUtils ;
1515import com .mapbox .api .directions .v5 .utils .ParseUtils ;
1616import com .mapbox .geojson .Point ;
17+ import com .ryanharter .auto .value .gson .Ignore ;
1718import java .io .UnsupportedEncodingException ;
1819import java .net .URL ;
1920import java .net .URLDecoder ;
@@ -366,11 +367,15 @@ public List<String> annotationsList() {
366367
367368 /**
368369 * A valid Mapbox access token used to making the request.
370+ * <p>
371+ * Avoiding to provide a token will most-likely result in a failure, however,
372+ * it's annotated as nullable to prevent serialization of tokens.
369373 *
370374 * @return a string representing the Mapbox access token
371375 */
372376 @ SerializedName ("access_token" )
373- @ NonNull
377+ @ Ignore (Ignore .Type .SERIALIZATION )
378+ @ Nullable
374379 public abstract String accessToken ();
375380
376381 /**
@@ -670,14 +675,38 @@ public static TypeAdapter<RouteOptions> typeAdapter(Gson gson) {
670675
671676 /**
672677 * Create a new instance of this class by passing in a formatted valid JSON String.
678+ * <p>
679+ * The Mapbox Access Token that was part of the original object was not serialized and needs
680+ * to be provided again.
681+ * The options will not be valid for a request without a Mapbox Access Token.
682+ *
683+ * @param json a formatted valid JSON string defining a RouteOptions
684+ * @param accessToken a Mapbox Access Token
685+ * @return a new instance of this class defined by the values passed inside this static factory
686+ * method
687+ * @see #fromUrl(URL)
688+ */
689+ @ NonNull
690+ public static RouteOptions fromJson (@ NonNull String json , @ Nullable String accessToken ) {
691+ return fromJson (json ).toBuilder ().accessToken (accessToken ).build ();
692+ }
693+
694+ /**
695+ * Create a new instance of this class by passing in a formatted valid JSON String.
696+ * <p>
697+ * The Mapbox Access Token that was part of the original object was not serialized and needs
698+ * to be provided again.
699+ * The options will not be valid for a request without a Mapbox Access Token so make sure to
700+ * provide a token with {@link #fromJson(String, String)}
701+ * or rebuild the options with {@link #toBuilder()}.
673702 *
674703 * @param json a formatted valid JSON string defining a RouteOptions
675704 * @return a new instance of this class defined by the values passed inside this static factory
676705 * method
677706 * @see #fromUrl(URL)
678707 */
679708 @ NonNull
680- public static RouteOptions fromJson (String json ) {
709+ public static RouteOptions fromJson (@ NonNull String json ) {
681710 GsonBuilder gson = new GsonBuilder ();
682711 gson .registerTypeAdapterFactory (DirectionsAdapterFactory .create ());
683712 return gson .create ().fromJson (json , RouteOptions .class );
@@ -689,7 +718,7 @@ public static RouteOptions fromJson(String json) {
689718 * @param url request URL
690719 * @return a new instance of this class defined by the values passed inside this static factory
691720 * method
692- * @see #fromJson(String)
721+ * @see #fromJson(String, String )
693722 */
694723 @ NonNull
695724 public static RouteOptions fromUrl (@ NonNull URL url ) {
@@ -1077,11 +1106,13 @@ public Builder annotationsList(@Nullable List<String> annotations) {
10771106 /**
10781107 * A valid Mapbox access token used to making the request.
10791108 *
1080- * @param accessToken a string containing a valid Mapbox access token
1109+ * @param accessToken a string containing a valid Mapbox access token.
1110+ * Avoiding to provide a token will most-likely result in a failure, however,
1111+ * it's annotated as nullable to prevent serialization of tokens.
10811112 * @return this builder for chaining options together
10821113 */
10831114 @ NonNull
1084- public abstract Builder accessToken (@ NonNull String accessToken );
1115+ public abstract Builder accessToken (@ Nullable String accessToken );
10851116
10861117 /**
10871118 * Exclude certain road types from routing. The default is to not exclude anything from the
0 commit comments