33import android .support .annotation .NonNull ;
44import android .support .annotation .Nullable ;
55import com .google .auto .value .AutoValue ;
6- import com .google .gson .FieldNamingPolicy ;
76import com .google .gson .Gson ;
87import com .google .gson .GsonBuilder ;
98import com .google .gson .JsonObject ;
109import com .google .gson .TypeAdapter ;
11- import com .google .gson .annotations .Expose ;
1210import com .google .gson .annotations .SerializedName ;
1311import com .mapbox .api .geocoding .v5 .GeocodingCriteria .GeocodingTypeCriteria ;
1412import com .mapbox .geojson .BoundingBox ;
1513import com .mapbox .geojson .Feature ;
1614import com .mapbox .geojson .Geometry ;
1715import com .mapbox .geojson .Point ;
18- import com .mapbox .geojson .gson .BoundingBoxDeserializer ;
1916import com .mapbox .geojson .gson .BoundingBoxSerializer ;
20- import com .mapbox .geojson .gson .GeoJsonAdapterFactory ;
2117import com .mapbox .geojson .gson .GeometryDeserializer ;
18+ import com .mapbox .geojson .gson .GeometryTypeAdapter ;
2219import com .mapbox .geojson .gson .PointDeserializer ;
23- import com .mapbox .geojson .gson .PointSerializer ;
2420
2521import java .io .Serializable ;
2622import java .util .List ;
4642@ AutoValue
4743public abstract class CarmenFeature implements Serializable {
4844
49- @ Expose
50- @ SerializedName ("type" )
5145 private static final String TYPE = "Feature" ;
5246
53- /**
54- * Create a new instance of this class by using the {@link Builder} class.
55- *
56- * @return this classes {@link Builder} for creating a new instance
57- * @since 3.0.0
58- */
59- public static Builder builder () {
60- return new AutoValue_CarmenFeature .Builder ();
61- }
62-
6347 /**
6448 * Create a CarmenFeature object from JSON.
6549 *
6650 * @param json string of JSON making up a carmen feature
6751 * @return this class using the defined information in the provided JSON string
6852 * @since 2.0.0
6953 */
54+ @ NonNull
7055 public static CarmenFeature fromJson (@ NonNull String json ) {
71- GsonBuilder gson = new GsonBuilder ();
72- gson .registerTypeAdapterFactory (GeocodingAdapterFactory .create ());
73- gson .registerTypeAdapterFactory (GeoJsonAdapterFactory .create ());
74- gson .registerTypeAdapter (Point .class , new PointDeserializer ());
75- gson .registerTypeAdapter (BoundingBox .class , new BoundingBoxDeserializer ());
76- gson .registerTypeAdapter (Geometry .class , new GeometryDeserializer ());
77- return gson .create ().fromJson (json , CarmenFeature .class );
56+ Gson gson = new GsonBuilder ()
57+ .registerTypeAdapter (Point .class , new PointDeserializer ())
58+ .registerTypeAdapter (Geometry .class , new GeometryDeserializer ())
59+ .registerTypeAdapterFactory (GeocodingAdapterFactory .create ())
60+ .create ();
61+ return gson .fromJson (json , CarmenFeature .class );
62+ }
63+
64+ /**
65+ * Create a new instance of this class by using the {@link Builder} class.
66+ *
67+ * @return this classes {@link Builder} for creating a new instance
68+ * @since 3.0.0
69+ */
70+ @ NonNull
71+ public static Builder builder () {
72+ return new AutoValue_CarmenFeature .Builder ()
73+ .type (TYPE );
7874 }
7975
76+ //
8077 // Feature specific attributes
78+ //
8179
8280 /**
8381 * This describes the TYPE of GeoJson geometry this object is, thus this will always return
@@ -88,9 +86,8 @@ public static CarmenFeature fromJson(@NonNull String json) {
8886 * @since 1.0.0
8987 */
9088 @ NonNull
91- public String type () {
92- return TYPE ;
93- }
89+ @ SerializedName ("type" )
90+ public abstract String type ();
9491
9592 /**
9693 * A {@link CarmenFeature} might have a member named {@code bbox} to include information on the
@@ -136,7 +133,9 @@ public String type() {
136133 @ NonNull
137134 public abstract JsonObject properties ();
138135
136+ //
139137 // CarmenFeature specific attributes
138+ //
140139
141140 /**
142141 * A string representing the feature in the requested language, if specified.
@@ -281,13 +280,14 @@ public static TypeAdapter<CarmenFeature> typeAdapter(Gson gson) {
281280 * @return a JSON string which represents this CarmenFeature
282281 * @since 3.0.0
283282 */
283+ @ SuppressWarnings ("unused" )
284284 public String toJson () {
285- GsonBuilder gson = new GsonBuilder ();
286- gson .registerTypeAdapter (Point .class , new PointSerializer ());
287- gson .registerTypeAdapter (BoundingBox .class , new BoundingBoxSerializer ());
288- gson . excludeFieldsWithModifiers ( java . lang . reflect . Modifier . TRANSIENT );
289- gson . setFieldNamingPolicy ( FieldNamingPolicy . LOWER_CASE_WITH_UNDERSCORES );
290- return gson .create (). toJson (this );
285+ Gson gson = new GsonBuilder ()
286+ .registerTypeAdapter (Geometry .class , new GeometryTypeAdapter ())
287+ .registerTypeAdapter (BoundingBox .class , new BoundingBoxSerializer ())
288+ . registerTypeAdapterFactory ( GeocodingAdapterFactory . create ())
289+ . create ( );
290+ return gson .toJson (this , CarmenFeature . class );
291291 }
292292
293293 /**
@@ -296,6 +296,7 @@ public String toJson() {
296296 * @return a new instance of {@link CarmenFeature} using the newly defined values
297297 * @since 3.0.0
298298 */
299+ @ SuppressWarnings ("unused" )
299300 public abstract Builder toBuilder ();
300301
301302 /**
@@ -304,8 +305,12 @@ public String toJson() {
304305 * @since 3.0.0
305306 */
306307 @ AutoValue .Builder
308+ @ SuppressWarnings ("unused" )
307309 public abstract static class Builder {
308310
311+ // Type will always be set to "Feature"
312+ abstract Builder type (@ NonNull String type );
313+
309314 /**
310315 * A Feature might have a member named {@code bbox} to include information on the coordinate
311316 * range for it's {@link Feature}s. The value of the bbox member MUST be a list of size 2*n
0 commit comments