All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.maplibre.geojson.gson.GeometryGeoJson Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
package org.maplibre.geojson.gson;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import com.google.gson.GsonBuilder;
import org.maplibre.geojson.Geometry;
import org.maplibre.geojson.GeometryAdapterFactory;

/**
 * This is a utility class that helps create a Geometry instance from a JSON string.
 * @since 4.0.0
 */
@Keep
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 4.0.0
   */
  public static Geometry fromJson(@NonNull String json) {

    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
    gson.registerTypeAdapterFactory(GeometryAdapterFactory.create());

    return gson.create().fromJson(json, Geometry.class);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy