FeatureCollection implements GeoJson { @Override public String toJson() { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); gson.registerTypeAdapterFactory(GeometryAdapterFactory.create()); return gson.create().toJson(this); } FeatureCollection(String type, @Nullable BoundingBox bbox, @Nullable List<Feature> features); static FeatureCollection fromJson(@NonNull String json); static FeatureCollection fromFeatures(@NonNull Feature[] features); static FeatureCollection fromFeatures(@NonNull List<Feature> features); static FeatureCollection fromFeatures(@NonNull Feature[] features,
                                               @Nullable BoundingBox bbox); static FeatureCollection fromFeatures(@NonNull List<Feature> features,
                                               @Nullable BoundingBox bbox); static FeatureCollection fromFeature(@NonNull Feature feature); static FeatureCollection fromFeature(@NonNull Feature feature,
                                              @Nullable BoundingBox bbox); @NonNull @Override String type(); @Nullable @Override BoundingBox bbox(); @Nullable List<Feature> features(); @Override String toJson(); static TypeAdapter<FeatureCollection> typeAdapter(Gson gson); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void toJson() throws IOException { final String json = loadJsonFixture(SAMPLE_FEATURECOLLECTION_BBOX); FeatureCollection geo = FeatureCollection.fromJson(json); compareJson(json, geo.toJson()); }