Skip to content

Commit

Permalink
move default method to an abstract class so that we can downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
“osana” committed Aug 29, 2018
1 parent 56470d3 commit 64ad552
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ subprojects {
}
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public void testToFromJson1() {
"heavy",
"heavy");

List<LegStep> steps = new ArrayList<>();

LegAnnotation annotation = LegAnnotation.builder()
.congestion(new ArrayList<String>())
.distance(distanceList)
Expand All @@ -84,7 +86,7 @@ public void testToFromJson1() {
.distance(53.4)
//.weight(14.3)
.duration(14.3)
.steps(new ArrayList<>())
.steps(steps)
.summary("")
.build();

Expand Down
23 changes: 0 additions & 23 deletions services-geojson/src/main/java/com/mapbox/geojson/Geometry.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.mapbox.geojson;

import android.support.annotation.NonNull;

import com.google.gson.GsonBuilder;
import com.mapbox.geojson.gson.GeoJsonAdapterFactory;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.PointDeserializer;

/**
* Each of the six geometries and {@link GeometryCollection}
* which make up GeoJson implement this interface.
Expand All @@ -15,20 +8,4 @@
*/
public interface Geometry extends GeoJson {

/**
* Create a new instance of this class by passing in a formatted valid JSON String.
*
* @param json a formatted valid JSON string defining a GeoJson Geometry
* @return a new instance of this class defined by the values passed inside this static factory
* method
* @since 3.0.0
*/
static Geometry fromJson(@NonNull String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
return gson.create().fromJson(json, Geometry.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mapbox.geojson;

import android.support.annotation.NonNull;

import com.google.gson.GsonBuilder;
import com.mapbox.geojson.gson.GeoJsonAdapterFactory;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.PointDeserializer;

/**
* This is a utility class that helps create a Geometry instance from a JSON string.
* @since 3.5.0
*/
public class GeometryGeoJson {

/**
* Create a new instance of Geometry class by passing in a formatted valid JSON String.
*
* @param json a formatted valid JSON string defining a GeoJson Geometry
* @return a new instance of Geometry class defined by the values passed inside
* this static factory method
* @since 3.5.0
*/
static Geometry fromJson(@NonNull String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
return gson.create().fromJson(json, Geometry.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GeometryTest extends TestUtils {
@Test
public void fromJson() throws IOException {
final String json = loadJsonFixture(SAMPLE_GEOMETRY_COLLECTION);
Geometry geo = Geometry.fromJson(json);
Geometry geo = GeometryGeoJson.fromJson(json);
assertEquals(geo.type(), "GeometryCollection");
}
}

0 comments on commit 64ad552

Please sign in to comment.