此时@RequestBody、@ResponseBody需要与@JsonProperty结合使用,才能做到请求正常解析,响应按要求格式返回。

注意@JsonProperty注解的位置需要加在getter方法上。

如果直接加在属性上,响应会这样返回:

{
"actionStatus": "OK",
"errorInfo": "success",
"errorCode": 0,
"ActionStatus": "OK",
"ErrorInfo": "success",
"ErrorCode": 0
}
正常实现的示例代码如下: @RequestMapping(value = "/tecentim/v1/callback", method = RequestMethod.POST)
@ResponseBody
public CallbackRsp imcallback(
@RequestParam String SdkAppid,
@RequestParam String CallbackCommand,
@RequestParam String contenttype,
@RequestParam String ClientIP,
@RequestParam String OptPlatform,
@RequestBody CallbackCommand command) { CallbackRsp result = new CallbackRsp();
result.setActionStatus("OK");
result.setErrorInfo("success");
result.setErrorCode(0); try { System.out.println("SdkAppid:"+SdkAppid);
System.out.println("CallbackCommand:"+CallbackCommand);
System.out.println("contenttype:"+contenttype);
System.out.println("ClientIP:"+ClientIP);
System.out.println("OptPlatform:"+OptPlatform);
System.out.println(command); } catch (DingDongFMException de) {
logger.error("imcallback failed", de);
} catch (Exception e) {
logger.error("imcallback failed", e);
}
return result;
}
import java.util.Arrays; import com.fasterxml.jackson.annotation.JsonProperty; public class CallbackCommand { private String CallbackCommand; //回调命令 private String GroupId; //产生群消息的群组 ID private String Type; //产生群消息的 群组类型,例如 Private,Public 和 ChatRoom private String From_Account; //消息发送者 ID private Integer MsgTime; //消息发送的时间戳,对应后台 Server 时间 private Integer MsgSeq; //消息序列号,唯一标示一条消息 private MsgBody[] MsgBody;//消息体,具体参见 消息格式描述 @JsonProperty(value = "CallbackCommand")
public String getCallbackCommand() {
return CallbackCommand;
}
public void setCallbackCommand(String callbackCommand) {
CallbackCommand = callbackCommand;
} @JsonProperty(value = "GroupId")
public String getGroupId() {
return GroupId;
}
public void setGroupId(String groupId) {
GroupId = groupId;
} @JsonProperty(value = "Type")
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
} @JsonProperty(value = "From_Account")
public String getFrom_Account() {
return From_Account;
}
public void setFrom_Account(String from_Account) {
From_Account = from_Account;
} @JsonProperty(value = "MsgTime")
public Integer getMsgTime() {
return MsgTime;
}
public void setMsgTime(Integer msgTime) {
MsgTime = msgTime;
} @JsonProperty(value = "MsgSeq")
public Integer getMsgSeq() {
return MsgSeq;
}
public void setMsgSeq(Integer msgSeq) {
MsgSeq = msgSeq;
} @JsonProperty(value = "MsgBody")
public MsgBody[] getMsgBody() {
return MsgBody;
}
public void setMsgBody(MsgBody[] msgBody) {
MsgBody = msgBody;
}
@Override
public String toString() {
return "CallbackCommand [CallbackCommand=" + CallbackCommand + ", GroupId=" + GroupId + ", Type=" + Type
+ ", From_Account=" + From_Account + ", MsgTime=" + MsgTime + ", MsgSeq=" + MsgSeq + ", MsgBody="
+ Arrays.toString(MsgBody) + "]";
} }
import com.fasterxml.jackson.annotation.JsonProperty; public class CallbackRsp { private String ActionStatus; private String ErrorInfo; private Integer ErrorCode; @JsonProperty(value = "ActionStatus")
public String getActionStatus() {
return ActionStatus;
} public void setActionStatus(String actionStatus) {
ActionStatus = actionStatus;
} @JsonProperty(value = "ErrorInfo")
public String getErrorInfo() {
return ErrorInfo;
} public void setErrorInfo(String errorInfo) {
ErrorInfo = errorInfo;
} @JsonProperty(value = "ErrorCode")
public Integer getErrorCode() {
return ErrorCode;
} public void setErrorCode(Integer errorCode) {
ErrorCode = errorCode;
} @Override
public String toString() {
return "CallbackRsp [ActionStatus=" + ActionStatus + ", ErrorInfo=" + ErrorInfo + ", ErrorCode=" + ErrorCode
+ "]";
} }

最新文章

  1. python3的基础练习题
  2. hihocoder #1341 Constraint Checker
  3. 跟着百度学PHP[4]OOP面对对象编程-8-继承
  4. git diff patch
  5. Codeforces Round #191 (Div. 2)
  6. HDU5593 ZYB's Tree 树形DP +分治
  7. rpm的一些用法
  8. 基于visual Studio2013解决面试题之0410计算二进制中1的个数
  9. SSH是什么?Linux如何修改SSH端口号?
  10. C语言和C++篇
  11. C# LocalizationHelpers (搬运)
  12. Java IO学习笔记总结
  13. echarts分组插件echarts.group代码分享
  14. 【Unity3D】Unity3D开发《我的世界》之三、创建一个Chunk
  15. Java进阶(二十四)Java List集合add与set方法原理简介
  16. Linux笔记2
  17. 语义分割之Dual Attention Network for Scene Segmentation
  18. Python高级网络编程系列之第三篇
  19. 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)
  20. scrapy 爬虫框架之持久化存储

热门文章

  1. CenOS下载离线依赖包神器--yumdownloader
  2. 解决IDEA更新为最新的2020.3版后,右键运行居然没有以xml形式运行的Run显示
  3. Codeforces Educational Round 94 (Rated for Div. 2)
  4. RabbitMQ Go客户端教程5——topic
  5. PyQt(Python+Qt)学习随笔:QColumnView的resizeGripsVisible属性
  6. MySQL(14)---Docker搭建MySQL主从复制(一主一从)
  7. 《Eroico》关卡与操作设计
  8. CF1407D Discrete Centrifugal Jumps 题解
  9. 【Codeforces 1181E】A Story of One Country (Easy & Hard)(分治 & set)
  10. docker 连接MySQL·集群