Skip to content

fix: json_serial returns bytes instead of str for non-UTF-8 binary va… - #2414

Open
Shubham-Padkonde wants to merge 1 commit into
geopython:masterfrom
Shubham-Padkonde:fix/json-serial-bytes-base64
Open

Shubham-Padkonde wants to merge 1 commit into
geopython:masterfrom
Shubham-Padkonde:fix/json-serial-bytes-base64

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

…lues

When json_serial() receives bytes that cannot be decoded as UTF-8, the fallback path calls base64.b64encode(), which returns bytes, not str. Returning bytes from a json.JSONEncoder default hook causes an immediate TypeError ("Object of type bytes is not JSON serializable") that defeats the entire purpose of the fallback.

Decode the base64 result to an ASCII string before returning so that the value can always be embedded in a JSON document.

Claude-Session: https://claude.ai/code/session_012acaiEt2JyZdUxjQndUWQL

Overview

Related Issue / discussion

Additional information

Dependency policy (RFC2)

  • I have ensured that this PR meets RFC2 requirements

Updates to public demo

Contributions and licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

  • I'd like to contribute [feature X|bugfix Y|docs|something else] to pygeoapi. I confirm that my contributions to pygeoapi will be compatible with the pygeoapi license guidelines at the time of contribution
  • I have already previously agreed to the pygeoapi Contributions and Licensing Guidelines

…lues

When json_serial() receives bytes that cannot be decoded as UTF-8, the
fallback path calls base64.b64encode(), which returns bytes, not str.
Returning bytes from a json.JSONEncoder default hook causes an immediate
TypeError ("Object of type bytes is not JSON serializable") that defeats
the entire purpose of the fallback.

Decode the base64 result to an ASCII string before returning so that
the value can always be embedded in a JSON document.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012acaiEt2JyZdUxjQndUWQL

This branch has not been deployed

No deployments
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.

2 participants