Skip to content

Commit

Permalink
removed AutoValue from geoJson (#953)
Browse files Browse the repository at this point in the history
* removed AutoValue from geoJson

* removing dependency on  PointDeserializer, PointSerializer,
BoundingBoxDeserializer and BoundingBoxSerializer,
GeometryDeserializer
in favor of TypeAdapters
  • Loading branch information
osana authored Mar 4, 2019
1 parent 4afbd73 commit 82837f3
Show file tree
Hide file tree
Showing 50 changed files with 2,625 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.GsonBuilder;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.PointSerializer;
import com.mapbox.geojson.PointAsCoordinatesTypeAdapter;

import java.io.Serializable;

Expand All @@ -24,7 +24,7 @@ public class DirectionsJsonObject implements Serializable {
public String toJson() {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointSerializer());
gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter());
return gson.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.google.gson.TypeAdapter;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.PointAsCoordinatesTypeAdapter;

import java.util.List;

Expand Down Expand Up @@ -129,7 +129,7 @@ public static TypeAdapter<DirectionsResponse> typeAdapter(Gson gson) {
public static DirectionsResponse fromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter());
return gson.create().fromJson(json, DirectionsResponse.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.PointAsCoordinatesTypeAdapter;

import java.util.List;

Expand Down Expand Up @@ -155,7 +155,7 @@ public static TypeAdapter<DirectionsRoute> typeAdapter(Gson gson) {
public static DirectionsRoute fromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter());
return gson.create().fromJson(json, DirectionsRoute.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.PointAsCoordinatesTypeAdapter;

import java.util.List;

Expand Down Expand Up @@ -334,7 +334,7 @@ public static TypeAdapter<RouteOptions> typeAdapter(Gson gson) {
public static RouteOptions fromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter());
return gson.create().fromJson(json, RouteOptions.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import com.mapbox.core.utils.MapboxUtils;
import com.mapbox.core.utils.TextUtils;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.Geometry;
import com.mapbox.geojson.GeometryAdapterFactory;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.gson.BoundingBoxTypeAdapter;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -71,11 +69,11 @@ protected MapboxGeocoding() {

@Override
protected GsonBuilder getGsonBuilder() {

return new GsonBuilder()
.registerTypeAdapterFactory(GeocodingAdapterFactory.create())
.registerTypeAdapter(Point.class, new PointDeserializer())
.registerTypeAdapter(Geometry.class, new GeometryDeserializer())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer());
.registerTypeAdapterFactory(GeometryAdapterFactory.create())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.GeoJson;
import com.mapbox.geojson.Geometry;
import com.mapbox.geojson.GeometryAdapterFactory;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
import com.mapbox.geojson.gson.BoundingBoxSerializer;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.GeometryTypeAdapter;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.gson.BoundingBoxTypeAdapter;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -55,10 +52,10 @@ public abstract class CarmenFeature implements GeoJson, Serializable {
*/
@NonNull
public static CarmenFeature fromJson(@NonNull String json) {

Gson gson = new GsonBuilder()
.registerTypeAdapter(Point.class, new PointDeserializer())
.registerTypeAdapter(Geometry.class, new GeometryDeserializer())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer())
.registerTypeAdapterFactory(GeometryAdapterFactory.create())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
.registerTypeAdapterFactory(GeocodingAdapterFactory.create())
.create();
CarmenFeature feature = gson.fromJson(json, CarmenFeature.class);
Expand Down Expand Up @@ -296,9 +293,10 @@ public static TypeAdapter<CarmenFeature> typeAdapter(Gson gson) {
@Override
@SuppressWarnings("unused")
public String toJson() {

Gson gson = new GsonBuilder()
.registerTypeAdapter(Geometry.class, new GeometryTypeAdapter())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxSerializer())
.registerTypeAdapterFactory(GeometryAdapterFactory.create())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
.registerTypeAdapterFactory(GeocodingAdapterFactory.create())
.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
import com.google.gson.TypeAdapter;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Geometry;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
import com.mapbox.geojson.gson.BoundingBoxSerializer;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.GeometryTypeAdapter;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.geojson.GeometryAdapterFactory;
import com.mapbox.geojson.gson.BoundingBoxTypeAdapter;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -41,9 +36,8 @@ public abstract class GeocodingResponse implements Serializable {
@NonNull
public static GeocodingResponse fromJson(@NonNull String json) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Point.class, new PointDeserializer())
.registerTypeAdapter(Geometry.class, new GeometryDeserializer())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer())
.registerTypeAdapterFactory(GeometryAdapterFactory.create())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
.registerTypeAdapterFactory(GeocodingAdapterFactory.create())
.create();
return gson.fromJson(json, GeocodingResponse.class);
Expand Down Expand Up @@ -123,8 +117,8 @@ public static Builder builder() {
@NonNull
public String toJson() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Geometry.class, new GeometryTypeAdapter())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxSerializer())
.registerTypeAdapterFactory(GeometryAdapterFactory.create())
.registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
.registerTypeAdapterFactory(GeocodingAdapterFactory.create())
.create();
return gson.toJson(this, GeocodingResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testNullProperties() {

@Test
public void testNullPropertiesJson() {
String jsonString = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.0, 38.0]}}";
String jsonString = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.0,38.0]}}";
CarmenFeature feature = CarmenFeature.fromJson(jsonString);

// Json( null Properties) -> Feature (empty Properties) -> Json(null Properties)
Expand Down
Loading

0 comments on commit 82837f3

Please sign in to comment.