Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

paulmach
Copy link
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
2 checks passed
@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