Skip to content

Add fromJson to all API response models #606

@cammace

Description

@cammace

Now that we are using AutoValue, the response objects which get created during the serialization of JSON require a type adapter factory which can often be confusing in times when you want to deserialize a JSON string into a DirectionsResponse for example. Doing so without adding the type adapter factory will result in:

Failed to invoke public com.mapbox.directions.v5.models.DirectionsRoute() with no args

To make this easier, I'm proposing we add a static factory method to all API model classes which would looks something like:

public static DirectionsResponse fromJson(String json) {
  return GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create()
      .fromJson(directionsRoute, DirectionsResponse.class);
}

cc: @zugaldia

Metadata

Metadata

Assignees

No one assigned

    Labels

    ArchivedIssue archived due to lack of activity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions