【问题标题】:Feign Client : Post a Map<String,Object> in Request Body => feign.FeignException: status 400 reading MApFeign 客户端:在请求正文中发布 Map<String,Object> => feign.FeignException:状态 400 读取 MAp
【发布时间】:2019-06-15 19:40:19
【问题描述】:

当我使用 Feign Client 发布 Map&lt;String,Object&gt; 时,我收到错误消息:

feign.FeignException: 读取 MAp 的状态 400。

代码

//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 { }
}

【问题讨论】:

    标签: java spring spring-cloud-feign


    【解决方案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 { }
    }
    

    【讨论】:

    • 很高兴我帮助了你:D
    • Ewerton,你是说第二个 sn-p 中的 HashSet 吗?
    猜你喜欢
    • 1970-01-01
    • 2015-12-22
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 2020-08-01
    相关资源
    最近更新 更多