paascloud/paascloud-master · error · IllegalArgumentException
JSON转换异常
Error message
JSON转换异常
What it means
IllegalArgumentException("JSON转换异常") thrown by OptSendSmsTopicConsumer.handlerSendSmsTopic when the SMS-topic message body fails to deserialize into SendSmsRequest via JacksonUtil.parseJson. Parsing is wrapped in try/catch and rethrown so malformed messages are rejected rather than processed with garbage data.
Solutions
- Read the error-level log containing the message body to identify malformed JSON vs schema mismatch
- Ensure the producer serializes SendSmsRequest with JacksonUtil.toJson and same field names
- Deploy producer and consumer together when SendSmsRequest changes
- Republish a valid message or remove the poison message to unblock the queue
Example fix
// before
sendSmsRequest = JacksonUtil.parseJson(body, SendSmsRequest.class);
// after
if (PublicUtil.isEmpty(body)) { log.warn("skip empty sms body, keys={}", keys); return; }
sendSmsRequest = JacksonUtil.parseJson(body, SendSmsRequest.class); Defensive patterns
Strategy: try-catch
Validate before calling
if (PublicUtil.isEmpty(body)) { log.warn("skip empty sms MQ body"); return; }
// producer side:
String body = JacksonUtil.toJson(sendSmsRequest); Try / catch
try {
sendSmsRequest = JacksonUtil.parseJson(body, SendSmsRequest.class);
} catch (Exception e) {
log.error("bad sms MQ body={}", body, e);
return; // route to dead-letter topic
} Prevention
- Always serialize SendSmsRequest with the same JSON library end-to-end
- Keep DTO field names stable across services
- Reject-and-dead-letter malformed messages instead of crash-looping
- Write an integration test publishing/consuming a sample message
When it happens
Trigger: MQ body on the send-sms topic is empty, invalid JSON, or JSON that does not match SendSmsRequest (wrong/missing fields, type mismatches such as phone number as number vs string).
Common situations: Producer/consumer DTO version skew after schema changes; producer sent the wrong payload type (e.g. the email request) to the SMS topic; message serialized with a different library or as plain text; encoding issues.
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/20c41da164d1bb40.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/consumer/OptSendSmsTopicConsumer.java:51
@Resource
private OptSmsService smsService;
/**
* Handler send sms topic.
*
* @param body the body
* @param topicName the topic name
* @param tags the tags
* @param keys the keys
*/
public void handlerSendSmsTopic(String body, String topicName, String tags, String keys) {
MqMessage.checkMessage(body, keys, topicName);
SendSmsRequest sendSmsRequest;
try {
sendSmsRequest = JacksonUtil.parseJson(body, SendSmsRequest.class);
} catch (Exception e) {
log.error("发送短信MQ出现异常={}", e.getMessage(), e);
throw new IllegalArgumentException("JSON转换异常", e);
}
String ipAddr = sendSmsRequest.getOutId();
if (StringUtils.isEmpty(ipAddr)) {
throw new IllegalArgumentException("outId不能为空");
}
smsService.sendSms(sendSmsRequest);
}
}
View on GitHub (pinned to 781281a950)