Skip to content

gmaps: emit both 'longitude' and 'longtitude' JSON keys#275

Open
boredland wants to merge 1 commit into
gosom:mainfrom
boredland:fix/longitude-json-key-alias
Open

gmaps: emit both 'longitude' and 'longtitude' JSON keys#275
boredland wants to merge 1 commit into
gosom:mainfrom
boredland:fix/longitude-json-key-alias

Conversation

@boredland
Copy link
Copy Markdown

Problem

The Entry.Longtitude field has shipped with the misspelled JSON key "longtitude" since the project started. The CSV exporter already uses the correct spelling (CsvHeaders[14] = "longitude" in gmaps/entry.go), but the JSON output and the Go struct field still use the typo.

Downstream consumers reading the JSON output either copy the typo into their schemas or have to work around it. I ran into this while wiring gosom into trinkhallen-data — naively reading longitude from the result silently dropped every record because the actual key is longtitude.

Fix

Renaming the JSON tag outright would break every existing parser, so this PR keeps the legacy key and adds the correctly spelled one as an alias:

  • MarshalJSON emits both "longtitude" (preserved verbatim) and "longitude" so new consumers can read the correct key and old consumers keep working.
  • UnmarshalJSON accepts either key; "longtitude" wins when both are present so existing data files round-trip byte-identical.

The Go struct field is intentionally left as Longtitude — renaming it would break every importer of the package. The field's doc comment now points new code at the correct JSON key.

Tests

Two new tests in gmaps/entry_test.go:

  • Test_EntryMarshalEmitsBothLongitudeKeys — verifies the output contains both keys with the same value.
  • Test_EntryUnmarshalAcceptsEitherLongitudeKey — verifies legacy, modern, and both-present inputs all populate Longtitude correctly.

Full test suite (go test ./gmaps/) and go vet ./gmaps/ both pass. Existing Test_EntryFromJSON* tests untouched.

Compatibility

  • JSON output: additive only. Every existing key keeps its name and value. New "longitude" key appears alongside.
  • JSON input: strictly more permissive. Was: only "longtitude" parsed. Now: either key parses.
  • Go API: unchanged. Entry.Longtitude remains exported with the same type.

The Entry.Longtitude field has shipped with the misspelled JSON key
"longtitude" since the project started. The CSV exporter already uses
the correct spelling (CsvHeaders[14] = "longitude"), but the JSON
output and the Go struct field are still misspelled. Downstream
consumers that read .json results either copy the typo or work around
it (we hit this in trinkhallen-data while parsing results to confirm
OSM enrichment matches).

Renaming the JSON tag outright would break every existing parser, so:

- MarshalJSON emits both "longtitude" (preserved verbatim) and
  "longitude" so downstream consumers can migrate without a flag day.
- UnmarshalJSON accepts either key; "longtitude" wins when both are
  present so existing data files round-trip byte-identical.

The Go struct field is intentionally left as Longtitude — renaming it
would break every importer of the package, and the field is documented
as deprecated in the comment so new code can prefer reading via JSON
unmarshal into Longitude-tagged structs.
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.

1 participant