File tree Expand file tree Collapse file tree
services-directions/src/test/java/com/mapbox/api/directions/v5/models
main/java/com/mapbox/geojson
test/java/com/mapbox/geojson Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,8 +49,8 @@ subprojects {
4949 }
5050 }
5151
52- sourceCompatibility = " 1.8 "
53- targetCompatibility = " 1.8 "
52+ sourceCompatibility = JavaVersion . VERSION_1_7
53+ targetCompatibility = JavaVersion . VERSION_1_7
5454
5555 dependencies {
5656
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ public void testToFromJson1() {
7171 "heavy" ,
7272 "heavy" );
7373
74+ List <LegStep > steps = new ArrayList <>();
75+
7476 LegAnnotation annotation = LegAnnotation .builder ()
7577 .congestion (new ArrayList <String >())
7678 .distance (distanceList )
@@ -84,7 +86,7 @@ public void testToFromJson1() {
8486 .distance (53.4 )
8587 //.weight(14.3)
8688 .duration (14.3 )
87- .steps (new ArrayList <>() )
89+ .steps (steps )
8890 .summary ("" )
8991 .build ();
9092
Original file line number Diff line number Diff line change 11package com .mapbox .geojson ;
22
3- import android .support .annotation .NonNull ;
4-
5- import com .google .gson .GsonBuilder ;
6- import com .mapbox .geojson .gson .GeoJsonAdapterFactory ;
7- import com .mapbox .geojson .gson .GeometryDeserializer ;
8- import com .mapbox .geojson .gson .PointDeserializer ;
9-
103/**
114 * Each of the six geometries and {@link GeometryCollection}
125 * which make up GeoJson implement this interface.
158 */
169public interface Geometry extends GeoJson {
1710
18- /**
19- * Create a new instance of this class by passing in a formatted valid JSON String.
20- *
21- * @param json a formatted valid JSON string defining a GeoJson Geometry
22- * @return a new instance of this class defined by the values passed inside this static factory
23- * method
24- * @since 3.0.0
25- */
26- static Geometry fromJson (@ NonNull String json ) {
27- GsonBuilder gson = new GsonBuilder ();
28- gson .registerTypeAdapterFactory (GeoJsonAdapterFactory .create ());
29- gson .registerTypeAdapter (Point .class , new PointDeserializer ());
30- gson .registerTypeAdapter (Geometry .class , new GeometryDeserializer ());
31- return gson .create ().fromJson (json , Geometry .class );
32- }
33-
3411}
Original file line number Diff line number Diff line change 1+ package com .mapbox .geojson .gson ;
2+
3+ import android .support .annotation .NonNull ;
4+
5+ import com .google .gson .GsonBuilder ;
6+ import com .mapbox .geojson .Geometry ;
7+ import com .mapbox .geojson .Point ;
8+
9+ /**
10+ * This is a utility class that helps create a Geometry instance from a JSON string.
11+ * @since 3.5.0
12+ */
13+ public class GeometryGeoJson {
14+
15+ /**
16+ * Create a new instance of Geometry class by passing in a formatted valid JSON String.
17+ *
18+ * @param json a formatted valid JSON string defining a GeoJson Geometry
19+ * @return a new instance of Geometry class defined by the values passed inside
20+ * this static factory method
21+ * @since 3.5.0
22+ */
23+ public static Geometry fromJson (@ NonNull String json ) {
24+ GsonBuilder gson = new GsonBuilder ();
25+ gson .registerTypeAdapterFactory (GeoJsonAdapterFactory .create ());
26+ gson .registerTypeAdapter (Point .class , new PointDeserializer ());
27+ gson .registerTypeAdapter (Geometry .class , new GeometryDeserializer ());
28+ return gson .create ().fromJson (json , Geometry .class );
29+ }
30+ }
Original file line number Diff line number Diff line change 11package com .mapbox .geojson ;
22
33import com .mapbox .core .TestUtils ;
4+ import com .mapbox .geojson .gson .GeometryGeoJson ;
45
56import org .junit .Test ;
67
@@ -15,7 +16,7 @@ public class GeometryTest extends TestUtils {
1516 @ Test
1617 public void fromJson () throws IOException {
1718 final String json = loadJsonFixture (SAMPLE_GEOMETRY_COLLECTION );
18- Geometry geo = Geometry .fromJson (json );
19+ Geometry geo = GeometryGeoJson .fromJson (json );
1920 assertEquals (geo .type (), "GeometryCollection" );
2021 }
2122}
You can’t perform that action at this time.
0 commit comments