-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move default method to a utility class so that we can downgrade to ja…
…va 7 (#876)
- Loading branch information
Showing
5 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
services-geojson/src/main/java/com/mapbox/geojson/gson/GeometryGeoJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mapbox.geojson.gson; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import com.mapbox.geojson.Geometry; | ||
import com.mapbox.geojson.Point; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
public 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters