Skip to content

Error parsing datacontenttype with charset specified #503

@andrejpk

Description

@andrejpk

When I try to use the Jackson parser to parse an MQTT CloudEvent that looks like this:

[
  {
    "id": "0d989854-5940-4721-9c8e-a09902e4592c",
    "source": "apk2-evgns-mqtt-demo",
    "type": "MQTT.EventPublished",
    "data": {
        "hello": "world"
      }
    },
    "time": "2023-01-09T21:43:16.226+00:00",
    "specversion": "1.0",
    "datacontenttype": "application/json; charset=utf-8",
    "subject": "devices/client-4/messages/d2c",
    "mqtttopic": "devices/client-4/messages/d2c"
  }
]

I get an error: com.fasterxml.jackson.databind.exc.MismatchedInputException: Wrong type OBJECT for attribute data, expecting STRING. Because content type is not a json, only a string is accepted as data

The problem seems to stem from the extended contenttype: application/json; charset=utf-8which is explicitly recommended in the MQTT binding docs.

I traced this to this line where the datacontentype is checked against a regexp that doesn't accept the semicolon and trailing format:

https://github.com/cloudevents/sdk-java/blob/master/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java#L221

It looks like #471 changed the way datacontenttype is checked with the prior implementation using a startswith check which would have worked.

Suggest adding a test case for the extended format and possibly whitespace support if the spec allows that too.

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