alibaba/spring-cloud-alibaba · error · RuntimeException
empty after conversion [messageConverter:%s,payloadClass:%s,
Error message
empty after conversion [messageConverter:%s,payloadClass:%s,payloadObj:%s]
What it means
In RocketMQMessageConverterSupport.convertMessage2MQ, for payloads that are neither String nor byte[], the configured Spring MessageConverter is asked to serialize the payload to JSON. If fromMessage returns null, the binder throws a RuntimeException detailing the converter class, payload class, and object - the payload could not be converted to a sendable form.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQMessageConverterSupport.java:124
}
private static org.apache.rocketmq.common.message.Message doConvert(String topic,
Message<?> message) {
Charset charset = Charset.defaultCharset();
Object payloadObj = message.getPayload();
byte[] payloads;
try {
if (payloadObj instanceof String payload) {
payloads = payload.getBytes(charset);
}
else if (payloadObj instanceof byte[] payload) {
payloads = payload;
}
else {
String jsonObj = (String) MESSAGE_CONVERTER.fromMessage(message,
payloadObj.getClass());
if (null == jsonObj) {
throw new RuntimeException(String.format(
"empty after conversion [messageConverter:%s,payloadClass:%s,payloadObj:%s]",
MESSAGE_CONVERTER.getClass(), payloadObj.getClass(),
payloadObj));
}
payloads = jsonObj.getBytes(charset);
}
}
catch (Exception e) {
throw new RuntimeException("convert to RocketMQ message failed.", e);
}
return getAndWrapMessage(topic, message.getHeaders(), payloads);
}
private static org.apache.rocketmq.common.message.Message getAndWrapMessage(
String topic, MessageHeaders headers, byte[] payloads) {
if (topic == null || topic.length() < 1) {
throw new IllegalArgumentException("topic must not be empty");
}View on GitHub (pinned to 115d590110)
Solutions
- Ensure a MessageConverter that handles your payload type is registered (e.g. Jackson for POJOs).
- Set the correct `contentType` header (e.g. application/json).
- Convert the payload to String/byte[] before sending if no converter fits.
- Debug which MESSAGE_CONVERTER is selected and why it returns null.
Example fix
// before
Message<String> ok = MessageBuilder.withPayload("hi").build();
Message<MyPojo> bad = MessageBuilder.withPayload(pojo).build(); // no converter -> [135]
// after
Message<MyPojo> good = MessageBuilder.withPayload(pojo)
.setHeader("contentType", "application/json").build(); // Jackson converter handles it Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight conversion check for unknown payload types.
if (!(payloadObj instanceof String) && !(payloadObj instanceof byte[])) {
Object out = MESSAGE_CONVERTER.fromMessage(message, payloadObj.getClass());
if (out == null) {
throw new IllegalArgumentException(
"No MessageConverter produces output for " + payloadObj.getClass()
+ " - set contentType or register a converter (avoids [135])");
}
} Type guard
// Type guard narrowing known-serializable payloads.
static boolean isDirectlySerializable(Object p) {
return p instanceof String || p instanceof byte[];
} Prevention
- Always set contentType for non-primitive payloads.
- Register a converter that covers your domain types.
- Pre-convert exotic payloads to String/byte[] when in doubt.
When it happens
Trigger: An outbound message has a non-String/non-byte[] payload whose MessageConverter.fromMessage(...) returns null (no converter handles the type, or it produced empty output).
Common situations: No suitable MessageConverter for the payload type; contentType header missing/mismatched so the chosen converter bails; a custom converter returning null on edge payloads; a payload object the converter cannot serialize.
Related errors
- convert to RocketMQ message failed.
- Binding for channel {destination.getName()} has been disable
- TransactionMQProducer must have a TransactionListener !!!
- message hasn't been sent,cause by : the SendType must be in
- topic must not be empty
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/34657ded7d787d89.
Report an issue: GitHub.