jason与字符串
java类
执行消息的参数类
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Data; /** * @Author: cjw * @Description: 执行消息事件请求dto * @Date: 2020/12/4 15:35 */ @Data // 对象与json转换时,属性名称大写转小写并以下划线连接 @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) // 转换时忽略掉不匹配的属性 @JsonIgnoreProperties(ignoreUnknown = true) public class ExecuteMessageRequestDto { /** * 数据id */ private Long dataId; /** * 当前处理人 */ private Long currentUserId; /** * 提交人 */ private Long applicantId; /** * 节点id */ private Long taskId; /** * 流程id */ private Long processId; /** * 扩展信息(注意引入的是com.fasterxml.jackson.databind.node.ObjectNode) */ private ObjectNode messageExtend; }
发送消息DTO
@Data @JsonNaming(SnakeCaseStrategy.class) public class SendMessageDto { private int type; private Long messageCode; private String messageContent; @NotEmpty private String receiver; private HashMap<String, String> variables; private SendSmsDto smsExtend; private SendMailDto mailExtend; // 微信消息扩展类 private SendWechatDto wechatExtend; }
微信消息扩展类
@Data
@JsonNaming(SnakeCaseStrategy.class) public class SendWechatDto { private String url; }
jason对象格式:
{
"entity_key":"ig_claim_list",
"currentUserId":1997,
"data_id":111,
"message_extend":{"url":"123456"}
}
jason字符串格式:
'{
"entity_key":"ig_claim_list",
"currentUserId":1997,
"data_id":111,
"message_extend":{"url":"123456"}
}'
使用jason对象作为参数,通过postMan调用接口,直接使用ExecuteMessageRequestDt接收参数
直接透传,传参如下
{
"entity_key":"ig_claim_list",
"currentUserId":1997,
"data_id":1,
"message_extend":{"send_wechat_dto":"{\"url\":\"123456\"}"}
}
java转换:
先使用ExecuteMessageRequestDto类直接接收参数
SendMessageDto sendMessageDto; if (Objects.nonNull(messageExtend)) {
// 如果messageExtend有值,则通过此方法会自动将值转换成对应的SendSmsDto/SendMailDto/SendWechatDto sendMessageDto = JacksonUtils.readValue(Objects.toString(messageExtend),SendMessageDto.class); } else { sendMessageDto = new SendMessageDto(); }