Changeset 13589 in josm


Ignore:
Timestamp:
2018-03-30T21:50:23+02:00 (9 months ago)
Author:
Don-vip
Message:

fix #16138 - do not output empty GeoJson geometries but null instead (as per ​RFC7946)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java

    r13587 r13589  
    1414import javax.json.Json;
    1515import javax.json.JsonArrayBuilder;
     16import javax.json.JsonObject;
    1617import javax.json.JsonObjectBuilder;
     18import javax.json.JsonValue;
    1719import javax.json.JsonWriter;
    1820import javax.json.stream.JsonGenerator;
     
    173175            propObj.add(t.getKey(), t.getValue());
    174176        }
     177        final JsonObject prop = propObj.build();
    175178
    176179        // Geometry
    177180        final JsonObjectBuilder geomObj = Json.createObjectBuilder();
    178181        p.accept(new GeometryPrimitiveVisitor(geomObj));
     182        final JsonObject geom = geomObj.build();
    179183
    180184        // Build primitive JSON object
    181185        array.add(Json.createObjectBuilder()
    182186                .add("type", "Feature")
    183                 .add("properties", propObj)
    184                 .add("geometry", geomObj));
     187                .add("properties", prop.isEmpty() ? JsonValue.NULL : prop)
     188                .add("geometry", geom.isEmpty() ? JsonValue.NULL : geom));
    185189    }
    186190
Note: See TracChangeset for help on using the changeset viewer.