Skip to content

Core JSONFormat treats mixed-case JSON media types as text #340

Backlog

Description

@yumingjs

Expected behavior

application/json and Application/JSON should produce the same data type. Media type and subtype names are case-insensitive (RFC 9110 §8.3.1, CloudEvents datacontenttype).

Actual behavior

The core JSON formatter reads the same binary-mode body as a dict for one spelling and a string for the other. When writing a structured event, it also turns a dict into a string for mixed-case JSON media types.

Steps to reproduce

from cloudevents.core.formats.json import JSONFormat

fmt = JSONFormat()
for media_type in ("application/json", "Application/JSON"):
    print(type(fmt.read_data(b'{"id": 42}', media_type)).__name__)

This prints dict, then str. This concerns the event payload's datacontenttype in the core formatter, independently of how a binding detects structured mode.

Specifications

  • Linux, Python 3.11.18
  • sdk-python main at c932f0b

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions