io.github.openfeign feign-core 9.5.0 io.github.openfeign feign-gson 9.5.0
@RestControllerpublic class MyRestController { @RequestMapping(value = "/person/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Person getPerson(@PathVariable Integer id) { Person p = new Person(); p.setId(id); p.setName("angus"); p.setAge(30); return p; }}
public interface HelloClient { @RequestLine("GET /hello") public String hello(); @RequestLine("GET /person/{id}") public Person getPerson(@Param("id") Integer id);}
public static void main(String[] args) { HelloClient client = Feign.builder().target(HelloClient.class, "http://localhost:8080"); String result = client.hello(); System.out.println(result); }
public static void main(String[] args) { HelloClient client = Feign.builder() .decoder(new GsonDecoder()) .target(HelloClient.class, "http://localhost:8080"); Person p = client.getPerson(1); System.out.println(p.getId()); System.out.println(p.getName()); System.out.println(p.getAge()); }