feign交互,個別參數沒法傳遞的問題

環境: spring boot 1.5.9+ feign+eurakespring

客戶端代碼:app

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

服務端代碼post

@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 類數據以下this

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;而後就進行了排除;debug

  • 1.排除客戶端代碼,debug發現pointNum的值不爲空
    1. 排除傳遞過程,使用httpAnalyzer攔截髮現poinNum有值
  • 3.使用了postman模擬調用接口,單獨傳遞pointNum,發現服務端報錯,fastJson沒法實例化類;

這樣結果已肯定,fastJson調用了一個非默認的構造器來實例化,那麼其餘的屬性就不會再set了.添加了一個無參默認構造器,pointNum的值就能夠正確傳遞了和接受了code

相關文章
相關標籤/搜索