private void writeProperties(JsonWriter out, Feature value) throws IOException { out.name(PROPERTIES_NAME); out.beginObject(); for(String key : value.properties().keySet()) { out.name(key); JsonElement propertyValue = gson.toJsonTree(value.properties().get(key)); gson.toJson(propertyValue, out); } out.endObject(); }
private void writeProperties(JsonWriter out, Feature value) throws IOException { out.name(PROPERTIES_NAME); out.beginObject(); for(String key : value.properties().keySet()) { out.name(key); JsonElement propertyValue = gson.toJsonTree(value.properties().get(key)); gson.toJson(propertyValue, out); } out.endObject(); }
@Test public void shouldHandleGeometryAsProperty() { Point point = Point.from(12.3, 45.3); Map<String, JsonElement> properties = new HashMap<>(); properties.put("test", toTest.toJsonTree(point)); Feature feature = FeatureUtils.featureWithProperties(properties); Feature parsed = toTest.fromJson(toTest.toJson(feature), Feature.class); assertThat(toTest.fromJson(parsed.properties().get("test"), Point.class), equalTo(point)); }
@Test public void shouldHandleNullProperties() { String nullPropertiesJson = "{" + "\"type\": \"Feature\", " + "\"geometry\": " + JsonUtils.givenPointJson(10,10) + ", " + "\"properties\": null" + "}"; Feature parsed = toTest.fromJson(nullPropertiesJson, Feature.class); assertThat(parsed.properties(), emptyMap()); }