当我使用Feign Client发布Map<String,Object>时,出现错误消息:

feign.FeignException:状态为400,读取MAp。


//Client side
@Component
@FeignClient(name = ServiceID.TACHE)
@RibbonClient(name = ServiceID.TACHE)
public interface ITacheService extends ITache {
@RequestMapping(value = TACHE_CONTROLLER + "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    Map<String, Object> save(@RequestBody Map<String,Object> map);
}

@Controller
@RequestMapping("/task")
public class TaskController {

// Server side
    @RequestMapping(value = "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    Map<String, Object> save(@RequestBody Map<String, Object> map) throws ParseException { }
}

最佳答案

您真的需要它作为地图吗?

尝试使用Hashset或HashMap之类的

//Client side
@Component
@FeignClient(name = ServiceID.TACHE)
@RibbonClient(name = ServiceID.TACHE)
public interface ITacheService extends ITache {
@RequestMapping(value = TACHE_CONTROLLER + "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    HashMap<String, Object> save(@RequestBody HashMap<String,Object> map);
}

@Controller
@RequestMapping("/task")
public class TaskController {

// Server side
    @RequestMapping(value = "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    HashMap<String, Object> save(@RequestBody HashMap<String, Object> map) throws ParseException { }
}

要么
//Client side
@Component
@FeignClient(name = ServiceID.TACHE)
@RibbonClient(name = ServiceID.TACHE)
public interface ITacheService extends ITache {
@RequestMapping(value = TACHE_CONTROLLER + "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    HashSet<String, Object> save(@RequestBody HashSet<String,Object> set);
}

@Controller
@RequestMapping("/task")
public class TaskController {

// Server side
    @RequestMapping(value = "/save", produces = {"application/json; charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    HashSet<String, Object> save(@RequestBody HashSet<String, Object> set) throws ParseException { }
}

09-26 17:47