Error parsing datacontenttype with charset specified
andrejpk opened this issue · 4 comments
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-8
which 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:
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.
Hi @andrejpk, I just published a new release 2.4.1 which includes the fix, please let me know if that fixes your issue
I'll test it out today, thank you, that was quick