Feign客户端:在请求正文中发布Map <string,object> => feign.FeignException:状态为400,读取MAp

时间:2019-01-22 10:45:06

标签: java spring spring-cloud-feign

当我使用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 { }
}

1 个答案:

答案 0 :(得分:1)

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

尝试使用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 { }
}