com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.la

短命女 2023-06-15 04:58 77阅读 0赞

全部的错误信息为:

  1. com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.lang.Integer` from String "女": not a valid Integer value
  2. at [Source: (PushbackInputStream); line: 1, column: 100] (through reference chain: com.shiyaxin.bean.User["sex"])

应用场景:
是再使用springCloud远程调用的时候

  1. //对用户操作的客户端接口
  2. @FeignClient(value = "sp")//标准该类是feign的客户端接口//需要指定微服务名字
  3. public interface UserClient {//注意接口类上不能写全局路径的映射-拼到方法里路径的前面
  4. /**
  5. * 调用需要进行操作的(指定)接口:为服务提供者的完整接口规则
  6. * (规则:把controller需要操作的的接口拿过来):
  7. */
  8. @GetMapping("/user/{id}")
  9. public **String** queryUserById(@PathVariable("id") Long id);
  10. }

消费者的调用服务提供者的controller类

  1. import com.shiyaxin.bean.User;
  2. import com.shiyaxin.client.UserClient;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.web.bind.annotation.*;
  5. @RequestMapping("feignConsumers/user")
  6. @RestController
  7. public class FeignUserController {
  8. //注入调用的模板类
  9. // @Autowired
  10. // RestTemplate restTemplate;
  11. //feign的动态代理
  12. @Autowired
  13. UserClient userClient;
  14. @GetMapping
  15. //RequestParam后的参数访问需要?参数
  16. public **String** queryUserById(@RequestParam("id")Long id) {
  17. /**
  18. * 需要toString,queryById的返回值是String
  19. */
  20. return this.userClient.queryUserById(id);
  21. }

客户端UserClient 接口类的方法的 public String queryUserById
public class FeignUserControlle类中的方法 public String queryUserById
本身的返回值是一个User对象,但是再返回页面的时候貌似要序列化(麻烦,暂时不需要),User对象客户端解析不了,就报了这个错,然后我就全部统一为String类型,

发表评论

表情:
评论列表 (有 0 条评论,77人围观)

还没有评论,来说两句吧...

相关阅读