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 27, 2018
1 parent 56470d3 commit eb5e999
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions build.gradle
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
23 changes: 0 additions & 23 deletions services-geojson/src/main/java/com/mapbox/geojson/Geometry.java
@@ -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);
}

}
@@ -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);
}
}
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 eb5e999

Please sign in to comment.