sysoalt/baba 2022-01-10 22:17 采纳率: 65%
浏览 72
已结题

通过Fegin请求接口返回失败

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图

通过fegin请求的controller

package com.example.controller;
import com.example.pojo.Ticket;
import com.example.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/consumer")
public class UserFeginController {

    @Autowired
    private TicketService ticketService = null;

    @GetMapping("/selectAll")
    public List<Ticket> selectAll(){
        return ticketService.selectAll();
    }

    @PostMapping("/insertTicket")
    public boolean insertTicket(){
        return ticketService.insertTicket();
    }

    @GetMapping("/getTicket/{id}")
    public Ticket getTicket(@PathVariable Long id){
        return ticketService.getTicket(id);
    }
}


请求的接口

package com.example.service;

import com.example.pojo.Ticket;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
@Service
@FeignClient(value = "PROVIDER-TICKET")
public interface TicketService {

    @GetMapping("/ticket/selectAll")
    public List<Ticket> selectAll();

    @PostMapping("/ticket/insertTicket")
    public boolean insertTicket();

    @GetMapping("/ticket/getTicket/{id}")
    public Ticket getTicket(@PathVariable("id") Long id);

}
运行结果及报错内容

控制台输出

2022-01-10 22:11:31.407  WARN 20484 --- [io-8081-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class com.example.pojo.Ticket and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.example.pojo.Ticket and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])

浏览器报错

img

我的解答思路和尝试过的方法

百度说添加getset方法,但是有@Data注解了

img

我想要达到的结果
  • 写回答

1条回答 默认 最新

  • zhang.yao Java领域新星创作者 2022-01-10 22:37
    关注

    重新设置下序列化属性 这个报错很明显啊 to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS 当对象为空的时候序列化失败,把这个限制关掉就好了
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月19日
  • 已采纳回答 1月11日
  • 修改了问题 1月11日
  • 创建了问题 1月10日

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)