Java Code Examples for com.google.gson.reflect.TypeToken#getParameterized()
The following examples show how to use
com.google.gson.reflect.TypeToken#getParameterized() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometryCollection.java From mapbox-java with MIT License | 4 votes |
@Override public void write(JsonWriter jsonWriter, GeometryCollection object) throws IOException { if (object == null) { jsonWriter.nullValue(); return; } jsonWriter.beginObject(); jsonWriter.name("type"); if (object.type() == null) { jsonWriter.nullValue(); } else { TypeAdapter<String> stringTypeAdapter = this.stringTypeAdapter; if (stringTypeAdapter == null) { stringTypeAdapter = gson.getAdapter(String.class); this.stringTypeAdapter = stringTypeAdapter; } stringTypeAdapter.write(jsonWriter, object.type()); } jsonWriter.name("bbox"); if (object.bbox() == null) { jsonWriter.nullValue(); } else { TypeAdapter<BoundingBox> boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; if (boundingBoxTypeAdapter == null) { boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; } boundingBoxTypeAdapter.write(jsonWriter, object.bbox()); } jsonWriter.name("geometries"); if (object.geometries() == null) { jsonWriter.nullValue(); } else { TypeAdapter<List<Geometry>> listGeometryAdapter = this.listGeometryAdapter; if (listGeometryAdapter == null) { TypeToken typeToken = TypeToken.getParameterized(List.class, Geometry.class); listGeometryAdapter = (TypeAdapter<List<Geometry>>) gson.getAdapter(typeToken); this.listGeometryAdapter = listGeometryAdapter; } listGeometryAdapter.write(jsonWriter, object.geometries()); } jsonWriter.endObject(); }
Example 2
Source File: GeometryCollection.java From mapbox-java with MIT License | 4 votes |
@Override public GeometryCollection read(JsonReader jsonReader) throws IOException { if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); return null; } jsonReader.beginObject(); String type = null; BoundingBox bbox = null; List<Geometry> geometries = null; while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); continue; } switch (name) { case "type": TypeAdapter<String> stringTypeAdapter = this.stringTypeAdapter; if (stringTypeAdapter == null) { stringTypeAdapter = gson.getAdapter(String.class); this.stringTypeAdapter = stringTypeAdapter; } type = stringTypeAdapter.read(jsonReader); break; case "bbox": TypeAdapter<BoundingBox> boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; if (boundingBoxTypeAdapter == null) { boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; } bbox = boundingBoxTypeAdapter.read(jsonReader); break; case "geometries": TypeAdapter<List<Geometry>> listGeometryAdapter = this.listGeometryAdapter; if (listGeometryAdapter == null) { TypeToken typeToken = TypeToken.getParameterized(List.class, Geometry.class); listGeometryAdapter = (TypeAdapter<List<Geometry>>) gson.getAdapter(typeToken); this.listGeometryAdapter = listGeometryAdapter; } geometries = listGeometryAdapter.read(jsonReader); break; default: jsonReader.skipValue(); } } jsonReader.endObject(); return new GeometryCollection(type == null ? "GeometryCollection" : type, bbox, geometries); }
Example 3
Source File: FeatureCollection.java From mapbox-java with MIT License | 4 votes |
@Override public void write(JsonWriter jsonWriter, FeatureCollection object) throws IOException { if (object == null) { jsonWriter.nullValue(); return; } jsonWriter.beginObject(); jsonWriter.name("type"); if (object.type() == null) { jsonWriter.nullValue(); } else { TypeAdapter<String> stringAdapter = this.stringAdapter; if (stringAdapter == null) { stringAdapter = gson.getAdapter(String.class); this.stringAdapter = stringAdapter; } stringAdapter.write(jsonWriter, object.type()); } jsonWriter.name("bbox"); if (object.bbox() == null) { jsonWriter.nullValue(); } else { TypeAdapter<BoundingBox> boundingBoxTypeAdapter = this.boundingBoxAdapter; if (boundingBoxTypeAdapter == null) { boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); this.boundingBoxAdapter = boundingBoxTypeAdapter; } boundingBoxTypeAdapter.write(jsonWriter, object.bbox()); } jsonWriter.name("features"); if (object.features() == null) { jsonWriter.nullValue(); } else { TypeAdapter<List<Feature>> listFeatureAdapter = this.listFeatureAdapter; if (listFeatureAdapter == null) { TypeToken typeToken = TypeToken.getParameterized(List.class, Feature.class); listFeatureAdapter = (TypeAdapter<List<Feature>>) gson.getAdapter(typeToken); this.listFeatureAdapter = listFeatureAdapter; } listFeatureAdapter.write(jsonWriter, object.features()); } jsonWriter.endObject(); }
Example 4
Source File: FeatureCollection.java From mapbox-java with MIT License | 4 votes |
@Override public FeatureCollection read(JsonReader jsonReader) throws IOException { if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); return null; } jsonReader.beginObject(); String type = null; BoundingBox bbox = null; List<Feature> features = null; while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); continue; } switch (name) { case "type": TypeAdapter<String> stringAdapter = this.stringAdapter; if (stringAdapter == null) { stringAdapter = gson.getAdapter(String.class); this.stringAdapter = stringAdapter; } type = stringAdapter.read(jsonReader); break; case "bbox": TypeAdapter<BoundingBox> boundingBoxAdapter = this.boundingBoxAdapter; if (boundingBoxAdapter == null) { boundingBoxAdapter = gson.getAdapter(BoundingBox.class); this.boundingBoxAdapter = boundingBoxAdapter; } bbox = boundingBoxAdapter.read(jsonReader); break; case "features": TypeAdapter<List<Feature>> listFeatureAdapter = this.listFeatureAdapter; if (listFeatureAdapter == null) { TypeToken typeToken = TypeToken.getParameterized(List.class, Feature.class); listFeatureAdapter = (TypeAdapter<List<Feature>>) gson.getAdapter(typeToken); this.listFeatureAdapter = listFeatureAdapter; } features = listFeatureAdapter.read(jsonReader); break; default: jsonReader.skipValue(); } } jsonReader.endObject(); return new FeatureCollection(type, bbox, features); }