/** Encode a complex attribute as a JSON object. */ private void encodeComplexAttribute( ComplexAttribute attribute, Map<NameImpl, String> attributes) { // get the attribute name and start a JSON object String name = attribute.getName().getLocalPart(); jsonWriter.key(name); if (attributes != null && !attributes.isEmpty()) { // we have some attributes to encode jsonWriter.array(); } // let's see if we have actually some properties to encode if (attribute.getProperties() != null && !attribute.getProperties().isEmpty()) { jsonWriter.object(); // encode the object properties, since this is not a top feature or a // chained feature we don't need to explicitly handle the geometry attribute encodeProperties(null, attribute.getType(), attribute.getProperties()); // end the attribute JSON object jsonWriter.endObject(); } if (attributes != null && !attributes.isEmpty()) { // encode the attributes list encodeAttributes(attributes); jsonWriter.endArray(); } }
/** Encodes a list of features (chained features) as a JSON array. */ private void encodeChainedFeatures(String attributeName, List<Feature> chainedFeatures) { // start the JSON object jsonWriter.key(attributeName); jsonWriter.array(); for (Feature feature : chainedFeatures) { // encode each chained feature jsonWriter.object(); encodeProperties(null, feature.getType(), feature.getProperties()); jsonWriter.endObject(); } // end the JSON chained features array jsonWriter.endArray(); }
/** Encode a feature in GeoJSON. */ protected void encodeFeature(Feature feature) { // start the feature JSON object jsonWriter.object(); jsonWriter.key("type").value("Feature"); // encode the feature identifier if available Identifier identifier = feature.getIdentifier(); if (identifier != null) { jsonWriter.key("id").value(identifier.getID()); } // geometry attribute has some special handling Property geometryAttribute = encodeGeometry(feature); // start the JSON object that will contain all the others properties jsonWriter.key("properties"); jsonWriter.object(); // encode object properties, we pass the geometry attribute to avoid duplicate encodings encodeProperties(geometryAttribute, feature.getType(), feature.getProperties()); // close the feature JSON object jsonWriter.endObject(); // close the properties JSON object jsonWriter.endObject(); }