feign交互,个别参数无法传递的问题

环境: spring boot 1.5.9+ feign+eurake

客户端代码:

@Component
@FeignClient("pubcloud-system")
public interface PointInterface {
    @PostMapping("/s/point/handlePointEvent")
    ResultInfo handlePointEvent(@RequestBody ObjectEvent event);
}

服务端代码

@RestController
@RequestMapping("/s/point")
public class PointServiceController {
    @Autowired
    private PointHandler pointHandler;
    @Autowired
    private PlatformUserPointService platformUserPointService;

    @PostMapping("/handlePointEvent")
    public ResultInfo handlePoint(@RequestBody ObjectEvent pointSupport) throws Exception {
        pointHandler.handle(pointSupport);
        return new ResultInfo(ResultCodeEnum.success);
    }
}

ObjectEvent 类数据如下

public class ObjectEvent extends ApplicationEvent implements PointSupport {
    private String activeCode;
    private String ObjectId;
    private String userId;
    private long pointNum;
    private String activeDescription;
    private String activeId;
    private String platformCode;
    public ObjectEvent(Object source, String activeCode, String objectId, String userId, String activeDescription) {
        super(source);
        this.activeCode = activeCode;
        ObjectId = objectId;
        this.userId = userId;
        this.activeDescription = activeDescription;
    }

    public ObjectEvent(Object source, String activeCode, String objectId, String userId, String activeDescription, String activeId, String platformCode) {
        super(source);
        this.activeCode = activeCode;
        ObjectId = objectId;
        this.userId = userId;
        this.activeDescription = activeDescription;
        this.activeId = activeId;
        this.platformCode = platformCode;
    }

 //略去get,set方法
}

调用时,发现pointNum的值总是为0;然后就进行了排除;

  • 1.排除客户端代码,debug发现pointNum的值不为空
    1. 排除传递过程,使用httpAnalyzer拦截发现poinNum有值
  • 3.使用了postman模拟调用接口,单独传递pointNum,发现服务端报错,fastJson无法实例化类;

这样结果已确定,fastJson调用了一个非默认的构造器来实例化,那么其他的属性就不会再set了.添加了一个无参默认构造器,pointNum的值就可以正确传递了和接受了

转载于:https://my.oschina.net/u/1590027/blog/3005857

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值