paascloud/paascloud-master · error · IllegalArgumentException
JSON转换异常
Error message
JSON转换异常
What it means
IllegalArgumentException("JSON转换异常") thrown by MdcTopicConsumer.handlerSendSmsTopic when the MQ message body cannot be deserialized into UpdateAttachmentDto via JacksonUtil.parseJson. The consumer guards the parse with try/catch and rethrows so the message is not silently dropped and the failure is visible to the broker's retry/dead-letter handling.
Solutions
- Log and inspect the offending message body (logged at error level) to see whether it is malformed JSON or a schema mismatch
- Confirm the producer serializes UpdateAttachmentDto with the same JacksonUtil/Jackson version and field names
- Roll out DTO changes to producer and consumer together, or make the consumer tolerant of unknown fields
- Send a corrected/republished message or skip it to unblock the queue
Example fix
// before
attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class);
// after
if (PublicUtil.isEmpty(body)) { log.warn("skip empty body, keys={}", keys); return; }
attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class); Defensive patterns
Strategy: try-catch
Validate before calling
if (PublicUtil.isEmpty(body)) { log.warn("skip empty MQ body"); return; }
// producer side:
String body = JacksonUtil.toJson(updateAttachmentDto); Try / catch
try {
attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class);
} catch (Exception e) {
log.error("bad MQ body={}", body, e);
return; // or send to dead-letter topic
} Prevention
- Serialize MQ payloads with JacksonUtil.toJson on the producer, never toString
- Keep producer and consumer DTO versions in sync
- Prefer tolerant deserialization (ignore unknown fields)
- Add a dead-letter path for poison messages
When it happens
Trigger: A message published to the attachment topic has a body that is not valid JSON, or valid JSON whose shape does not match UpdateAttachmentDto (missing required fields, wrong types), or is empty/null.
Common situations: Producer and consumer use different DTO versions after a schema change; producer sent a plain string/URL instead of a JSON payload; message serialized by a non-Jackson serializer (e.g. raw toString) or with a different encoding.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/3d4c58b04ade9331.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/consumer/MdcTopicConsumer.java:63
* @param tags the tags
* @param keys the keys
*/
@Transactional(rollbackFor = Exception.class)
public void handlerSendSmsTopic(String body, String topicName, String tags, String keys) throws QiniuException {
MqMessage.checkMessage(body, keys, topicName);
if (StringUtils.equals(tags, AliyunMqTopicConstants.MqTagEnum.DELETE_ATTACHMENT.getTag())) {
List<Long> idList = opcAttachmentService.queryAttachmentByRefNo(body);
for (final Long id : idList) {
opcAttachmentService.deleteFile(id);
}
} else {
UpdateAttachmentDto attachmentDto;
try {
attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class);
} catch (Exception e) {
log.error("发送短信MQ出现异常={}", e.getMessage(), e);
throw new IllegalArgumentException("JSON转换异常", e);
}
opcAttachmentService.updateAttachment(attachmentDto);
}
}
}
View on GitHub (pinned to 781281a950)