springspring-cloud-feignfeign

Spring Feign: Could not extract response: no suitable HttpMessageConverter found for response type


I am trying to get a Spring Cloud Netflix Feign client to fetch a bit of JSON over HTTP and convert it to an object. I keep getting this error instead:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class io.urig.checkout.Book] and content type [application/json;charset=UTF-8]

Here's the bit of JSON returned from the remote service:

{
    "id": 1,
    "title": "Moby Dick",
    "author": "Herman Melville"
}

Here's the corresponding class I'm trying to deserialize to:

package io.urig.checkout;

public class Book {
    private long id;
    private String title;
    private String author;

    public Book() {}

    public Book(long id, String title, String author) {
        super();
        this.id = id;
        this.title = title;
        this.author = author;
    }

    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}

And here's my Feign client:

package io.urig.checkout;

import java.util.Optional;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import io.urig.checkout.Book;

@FeignClient(name="inventory", url="http://localhost:8080/")
public interface InventoryClient {

    @RequestMapping(method = RequestMethod.GET, value = "books/{bookId}")
    public Optional<Book> getBookById(@PathVariable(value="bookId") Long bookId);

}

What do I need to do to get this to work?


Solution

  • Thanks to all who tried to help!

    As it turned out my issue was a defective Maven dependency, probably corrupted during download or installation. Having entirely deleted the .m2/repository folder on my machine and then updating Maven dependencies for the project the issue is now gone.