spring-guides / gs-rest-service

Building a RESTful Web Service :: Learn how to create a RESTful web service with Spring.

Home Page:https://spring.io/guides/gs/rest-service/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Rest Service Tutorial "gs-rest-service" - No converter found for return value of type: class hello.Greeting

GWReeves opened this issue · comments

Hi Guys,
I am having a problem running the Spring Rest Service Tutorial... gs-rest-service
(See: "https://spring.io/guides/gs/rest-service/")

There appears to be issues around mapping Java/JSON.

The error I get is...
"No converter found for return value of type: class hello.Greeting"
The URL I'm using...
"http://localhost:8080/greeting?name=User"
I'm running the app from within STS as...
"Spring Boot App"

My environment is:

Windows 7
Java 8 (1.8.0_144)
Maven 3.5.2
Spring Tool Suite Version: 3.9.1.RELEASE ( Platform: Eclipse Oxygen.1a (4.7.1a) )

It happens with both the self-built "gs-rest-service-initial" and the completed version "gs-rest-service-complete"

These are things I've already checked after reading other peoples suggestions...

Yes, the Greeting does have getters
The jackson databind, annotaions and core libraries are present (all at version 2.8.10)
I tried commenting out the org.springframework.boot in the pom.xml but it made it worse
I also tried restarting STS but it had no effect

I also tied exporting it as a jar to run outside of STS but I got all kinds of issues but that may have been my "jar-ing"
I did an export as runnable jar with the option "Package required libraries into generated jar"

Anyone have any ideas?

Thanks

Hi GWReeves,

I had the same issue to resolve it: I overwrite Spring default dependencies for JSON in pom.xml like this:

<!-- JSON via Jackson --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.5.3</version> </dependency>

In my case, I had this issue because the jackson-databind jar was corrupt. It worked after deleting such jar and recompiling.

At the time of writing the project uses Jackson library version 2.9.5. I was able to work around the "No converter found for return value of type: class hello.Greeting" issue by downgrading to 2.9.4.

<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-databind</artifactId>
	<version>2.9.4</version>
</dependency>
<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-annotations</artifactId>
	<version>2.9.4</version>
</dependency>
<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-core</artifactId>
	<version>2.9.4</version>
</dependency>

At least since upgrading to Spring Boot 2.0.2.RELEASE it works for me.

screen shot 2018-05-15 at 10 16 58 am

I had just exlude com.fasterxml.jackson.core from spring-boot-starter-web

org.springframework.boot
spring-boot-starter-web


com.fasterxml.jackson.core



and added the dependencies like @kekbur and all things work well
thanks all