LineString implements CoordinateContainer<List<Point>> { public static LineString fromJson(String json) { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); return gson.create().fromJson(json, LineString.class); } LineString(String type, @Nullable BoundingBox bbox, List<Point> coordinates); static LineString fromJson(String json); static LineString fromLngLats(@NonNull MultiPoint multiPoint); static LineString fromLngLats(@NonNull List<Point> points); static LineString fromLngLats(@NonNull List<Point> points, @Nullable BoundingBox bbox); static LineString fromLngLats(@NonNull MultiPoint multiPoint, @Nullable BoundingBox bbox); static LineString fromPolyline(@NonNull String polyline, int precision); @NonNull @Override String type(); @Nullable @Override BoundingBox bbox(); @NonNull @Override List<Point> coordinates(); @Override String toJson(); String toPolyline(int precision); static TypeAdapter<LineString> typeAdapter(Gson gson); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void fromJson() throws IOException { final String json = "{\"type\": \"LineString\"," + " \"coordinates\": [[ 100, 0], [101, 1]]} "; LineString geo = LineString.fromJson(json); assertEquals(geo.type(), "LineString"); assertEquals(geo.coordinates().get(0).longitude(), 100.0, 0.0); assertEquals(geo.coordinates().get(0).latitude(), 0.0, 0.0); assertFalse(geo.coordinates().get(0).hasAltitude()); }
@Test public void fromJson_coordinatesPresent() throws Exception { thrown.expect(NullPointerException.class); LineString.fromJson("{\"type\":\"LineString\",\"coordinates\":null}"); }