Skip to content

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

Merged
paulmach merged 1 commit intomasterfrom
json-null
Jan 29, 2024
Merged

geojson: null json into non-pointer Feature/FeatureCollection will set them to empty#145
paulmach merged 1 commit intomasterfrom
json-null

Conversation

@paulmach
Copy link
Copy Markdown
Owner

fixes #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

@paulmach paulmach merged commit 12b0e24 into master Jan 29, 2024
@paulmach paulmach deleted the json-null branch January 29, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON Unmarshalling panics if the geojson object is null

1 participant