Opened 6 months ago

Closed 4 months ago

#5597 closed defect (fixed)

ST_AsGeoJSONRow: Invalid output for null geometry

Reported by: jtojnar Owned by: pramsey
Priority: medium Milestone: PostGIS 3.5.0
Component: postgis Version: 3.4.x
Keywords: json Cc:

Description

According to the GeoJSON RFC, the `type` member of Geometry must be one of seven geometry type names. This is not the case when a row containing a NULL geometry column is converted to GeoJSON Feature:

postgres=# select ST_AsGeoJSON(r.*) from (values (null::geometry)) as r(geom);
                           st_asgeojson                            
-------------------------------------------------------------------
 {"type": "Feature", "geometry": {"type": null}, "properties": {}}
(1 row)

The proper representation is "geometry": null, see section 3.2.

This can be trivially fixed but I am not sure whether it would be an acceptable BC break.

Change History (3)

comment:1 by robe, 6 months ago

Milestone: PostGIS 3.4.1PostGIS 3.5.0

Probably safer to just put in 3.5.0 where we allow breaking changes, just in case someone is actually relying on this non-standard behavior.

comment:2 by robe, 5 months ago

jtojnar if you want to provide a patch for this, I think it's fine to go into 3.5.0. 3.4 or lower we'd have to seriously think about it. I doubt anyone is relying on the old representation of null geometries in older versions but who knows.

comment:3 by Paul Ramsey <pramsey@…>, 4 months ago

Resolution: fixed
Status: newclosed

In 2962a36/git:

ST_AsGeoJSON, produce correct output in null geometry case, closes #5597

Note: See TracTickets for help on using tickets.