Skip to content

AbstractJackson2MessageConverter does not work with other ObjectMappers from jackson-dataformats-binary #3038

@ajafff

Description

@ajafff

In what version(s) of Spring AMQP are you seeing this issue?

For example:

3.2.4

Describe the bug

Example uses CBORMapper from jackson-dataformat-cbor

To Reproduce

  • Use RabbitTemplate#convertAndSend() to serialize an object and send it to a queue
  • Use @RabbitListener to read message from queue and deserialize to object

Expected behavior

Serializing and sending works.
Deserializing does not work because convertBytesToObject converts the payload to UTF-8 string before handing it to the ObjectMapper, causing Can not create parser for non-byte-based source.
I could get deserialization to work if I add a ;charset=ascii to the MimeType, as that causes the raw payload to be handed to the ObjectMapper. Unfortunately this hack causes serialization to fail, because it now calls ObjectMapper#writeValueAsString which is not supported for CBOR.

This is basically asking for it to work out of the box, or being able to override convertBytesToObject (currently private) and a new method convertObjectToBytes (so that I don't have to override and copy the contents of createMessage)

Sample

public class CborMessageConverter extends AbstractJackson2MessageConverter {
    public CborMessageConverter() {
        super(new CBORMapper(), MimeTypeUtils.parseMimeType("application/cbor"));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions