paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
886 stars 103 forks source link

geojson: `null` json into non-pointer Feature/FeatureCollection will set them to empty #145

Closed paulmach closed 7 months ago

paulmach commented 7 months ago

fixes https://github.com/paulmach/orb/issues/144

If you have { feature: null } and you're trying to unmarshal it into something like

type Struct struct {
    Feature geojson.Feature `json:"feature"`
}

you'd get a panic. This fix sets Struct.Feature to an empty object. I think this is the correct behavior as you might have { isFeature: true, feature: null } and you're code would check isFeature first.

If you really care about if it's null vs. empty you should model your data as

type Struct struct {
    Feature *geojson.Feature `json:"feature"`
}

the check Struct.Feature != nil