GeometryCollection implements Geometry { public static GeometryCollection fromJson(String json) { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); gson.registerTypeAdapterFactory(GeometryAdapterFactory.create()); return gson.create().fromJson(json, GeometryCollection.class); } GeometryCollection(String type, @Nullable BoundingBox bbox, List<Geometry> geometries); static GeometryCollection fromJson(String json); static GeometryCollection fromGeometries(@NonNull List<Geometry> geometries); static GeometryCollection fromGeometries(@NonNull List<Geometry> geometries,
                                                  @Nullable BoundingBox bbox); static GeometryCollection fromGeometry(@NonNull Geometry geometry); static GeometryCollection fromGeometry(@NonNull Geometry geometry,
                                                @Nullable BoundingBox bbox); @NonNull @Override String type(); @Nullable @Override BoundingBox bbox(); @NonNull List<Geometry> geometries(); @Override String toJson(); static TypeAdapter<GeometryCollection> typeAdapter(Gson gson); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void fromJson() throws IOException { final String json = " { \"type\": \"GeometryCollection\"," + " \"bbox\": [120, 40, -120, -40]," + " \"geometries\": [" + " { \"type\": \"Point\"," + " \"bbox\": [110, 30, -110, -30]," + " \"coordinates\": [100, 0]}," + " { \"type\": \"LineString\"," + " \"bbox\": [110, 30, -110, -30]," + " \"coordinates\": [[101, 0], [102, 1]]}]}"; GeometryCollection geo = GeometryCollection.fromJson(json); assertEquals(geo.type(), "GeometryCollection"); assertEquals(geo.geometries().get(0).type(), "Point"); assertEquals(geo.geometries().get(1).type(), "LineString"); }