相关文章推荐
淡定的盒饭  ·  ASP.NET 核心 Blazor ...·  3 周前    · 
傻傻的馒头  ·  STRING_SPLIT ...·  3 周前    · 
犯傻的黄豆  ·  Branches API | GitLab ...·  4 天前    · 
兴奋的口罩  ·  svm ...·  1 年前    · 
讲道义的烈酒  ·  PyQt ...·  1 年前    · 
瘦瘦的烤红薯  ·  git cherry-pick ...·  2 年前    · 

在使用feign调用其他服务接口时,如果对象存在Date类型就会报错Cannot deserialize value of type java.util.Date from String

解决方法1:在调用端的model类上加上注解,必须有无参构造器
@JsonFormat(pattern = “yyyy-MM-dd”, timezone = “GMT+8”)

@FeignClient(value = "${feignTestArms}",fallbackFactory = FeignClientTestFactory.class)
public interface FeignTest {
    @RequestMapping(value = "/pow/arms/v1/integration/organization/ba",method = RequestMethod.GET)
    List<TestModel> getAllOrganizations();
package com.gsafety.pow.integration.feign.client.hystrix;
import com.gsafety.pow.integration.feign.client.FeignTest;
import com.gsafety.pow.integration.model.resource.OrganizationModel;
import com.gsafety.pow.integration.model.resource.TestModel;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class FeignClientTestFactory implements FallbackFactory<FeignTest> {
    @Override
    public FeignTest create(Throwable cause) {
        return new FeignTest() {
            @Override
            public List<TestModel> getAllOrganizations() {
                System.out.println("kang");
                cause.printStackTrace();
                return null;
package com.gsafety.pow.integration.model.resource;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
public class TestModel {
    private String name;
    private String value;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
    private Date startTime;
    public TestModel(){
    public TestModel(String name, String value,Date startTime) {
        this.name = name;
        this.value = value;
        this.startTime = startTime;
    public String getName() {
        return name;
    public Date getStartTime() {
        return startTime;
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    public void setName(String name) {
        this.name = name;
    public String getValue() {
        return value;
    public void setValue(String value) {
        this.value = value;

解决方法2:调用时,返回object类型,然后通过JSONObject 解析成实体类

@FeignClient(value = "${feignTestArms}",fallbackFactory = FeignClientTestFactory.class)
public interface FeignTest {
    @RequestMapping(value = "/pow/arms/v1/integration/organization/ba",method = RequestMethod.GET)
    Object getAllOrganizations();
package com.gsafety.pow.integration.feign.client;
import com.alibaba.fastjson.JSONObject;
import com.gsafety.pow.integration.model.resource.OrganizationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController(value = "kang/")
@RequestMapping("/kang")
public class FeignTestController {
    @Autowired
    private FeignTest feignTest;
    @GetMapping(value = "/feignTest")
    public List getOrgans() {
        Object allOrganizations = feignTest.getAllOrganizations();
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(allOrganizations));
        System.out.println("kang" + jsonObject);
        String data = jsonObject.getString("data");
        List list = JSONObject.parseObject(data, List.class);
        return list;
//        return feignTest.getAllOrganizations();
				An operation on a socket could not be performed because the system lacked sufficient buffer space or