/** * Write a java.util.Map out as a JSON Object. Keys are serialized using the toString method of * the object and values are serialized using primitives conversions. If a value in the map is a * List or Map object, it will be serialized as JSON Array or JSON Object respectively. * * @param map a java.util.Map object to be serialized as a JSON Object */ public JSONBuilder writeMap(final Map map) { this.object(); for (final Object k : map.keySet()) { this.key(k.toString()); this.value(map.get(k)); } return this.endObject(); }
/** * Write a java.util.List out as a JSON Array. The values of the array will be converted using * ike standard primitive conversions. If the list contains List or Map objects, they will be * serialized as JSON Arrays and JSON Objects respectively. * * @param list a java.util.List to be serialized as JSON Array */ public JSONBuilder writeList(final List list) { this.array(); for (final Object o : list) { this.value(o); } return this.endArray(); }
private void writeCrsLegacy(final GeoJSONBuilder jsonWriter, CoordinateReferenceSystem crs) { // Coordinate Reference System, currently only if the namespace is // EPSG if (crs != null) { Set<ReferenceIdentifier> ids = crs.getIdentifiers(); // WKT defined crs might not have identifiers at all if (ids != null && ids.size() > 0) { NamedIdentifier namedIdent = (NamedIdentifier) ids.iterator().next(); String csStr = namedIdent.getCodeSpace().toUpperCase(); if (csStr.equals("EPSG")) { jsonWriter.key("crs"); jsonWriter.object(); jsonWriter.key("type").value(csStr); jsonWriter.key("properties"); jsonWriter.object(); jsonWriter.key("code"); jsonWriter.value(namedIdent.getCode()); jsonWriter.endObject(); // end properties jsonWriter.endObject(); // end crs } } } }
/** * Encode a simple attribute, this means that this property will be encoded as a simple JSON * attribute if no attributes are available, otherwise it will be encoded as an array containing * the value and attributes values. */ private void encodeSimpleAttribute( String name, Object value, Map<NameImpl, String> attributes) { // let's see if we need to encode attributes or simple value if (attributes == null || attributes.isEmpty()) { // add a simple JSON attribute to the current object jsonWriter.key(name).value(value); return; } // we need to encode a list of attributes, let's first encode the main value jsonWriter.key(name).array(); jsonWriter.value(value); // encode the attributes list encodeAttributes(attributes); // close the values \ attributes array jsonWriter.endArray(); }
@Override public void addFeature(String layerName, String featureId, String geometryName, Geometry aGeom, Map<String, Object> properties) { if (precisionReducerFilter != null) { aGeom.apply(precisionReducerFilter); } jsonWriter.object(); jsonWriter.key("type").value("Feature"); jsonWriter.key("id").value(featureId); jsonWriter.key("geometry"); // Write the geometry, whether it is a null or not jsonWriter.writeGeom(aGeom); jsonWriter.key("geometry_name").value(geometryName); jsonWriter.key("properties"); jsonWriter.object(); for (Map.Entry<String, Object> e : properties.entrySet()) { String attributeName = e.getKey(); Object value = e.getValue(); jsonWriter.key(attributeName); if (value == null) { jsonWriter.value(null); } else { jsonWriter.value(value); } } jsonWriter.endObject(); // end the properties jsonWriter.endObject(); // end the feature }
private void writeCrs(final GeoJSONBuilder jsonWriter, CoordinateReferenceSystem crs) throws FactoryException { if (crs != null) { String identifier = null; Integer code = CRS.lookupEpsgCode(crs, true); if (code != null) { if (code != null) { identifier = SrsSyntax.OGC_URN.getPrefix() + code; } } else { identifier = CRS.lookupIdentifier(crs, true); } jsonWriter.key("crs"); jsonWriter.object(); jsonWriter.key("type").value("name"); jsonWriter.key("properties"); jsonWriter.object(); jsonWriter.key("name"); jsonWriter.value(identifier); jsonWriter.endObject(); // end properties jsonWriter.endObject(); // end crs } else { jsonWriter.key("crs"); jsonWriter.value(null); } }
} else { jsonWriter.value(null);
this.object(); this.key("type"); this.value(getGeometryName(geometry));