go-spatial / geom

Geometry interfaces to help drive interoperability within the Go geospatial community
MIT License
173 stars 38 forks source link

geojson.Geometry.UnmarshalJSON() panics if JSON doesn't have the right format #118

Closed vincentvaroquauxads closed 3 years ago

vincentvaroquauxads commented 3 years ago

I had an issue with a JSON file where the field "type" was missing.

The function func (geo *Geometry) UnmarshalJSON(b []byte) error panics when it tries to dereference geojsonMap["type"].

I think it will be the same if "geometries" or "coordinates" is missing.

The function must check that key exists before dereferencing geojsonMap[key].

Thanks !

gdey commented 3 years ago

Good catch. I will look into this.