DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Engineering Closed-Loop Graph-RAG Systems, Part 3: Closing the Loop in Graph-RAG Systems
  • Detecting Plan Regression in SQL Server Using Query Store
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • A Deep Dive into Tracing Agentic Workflows (Part 2)
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot RestController Error: “No Converter Found for Return Value of Type”

Spring Boot RestController Error: “No Converter Found for Return Value of Type”

Have you come across this error? Let's take a look at how this happens and how public getters are one possible solution to the problem.

By 
Kevin Hooke user avatar
Kevin Hooke
·
Feb. 23, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
123.0K Views

Join the DZone community and get the full member experience.

Join For Free

Spring Boot RestControllers, by default, can return a POJO class as the return result from a mapped request method, and it is converted into a JSON result. I’ve run into this issue before though, and it’s not immediately obvious what’s wrong: ‘No converter found for return value of type’:

java.lang.IllegalArgumentException: No converter found for return value 
of type: class kh.springboot.redis.domain.RedisResult
at org.springframework.web.servlet.mvc.method.annotation
.AbstractMessageConverterMethodProcessor
.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:187) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]


My returned class from my @GetMapping method is just a simple POJO:

public class RedisResult {

    private String key;
    private String value;

    public RedisResult(String key, String value) {
        this.key = key;
        this.value = value;
    }
}


And my @RestController is a simple controller with a single @GetMapping (in this case I’m building a REST endpoint to query key values from Redis using Spring Data Redis RedisTemplate:

@RestController

public class RedisRestController {

    @Autowired
    @Qualifier("RedisTemplate")
    private RedisTemplate template;

    @GetMapping("singlekey/{key}")
    public RedisResult getSingleValue(@PathVariable("key") String key){
        String value = (String)this.template.opsForValue().get(key);
        RedisResult result = new RedisResult(key, value);
        return result;
    }
}


If you’ve found my post because you have this same issue, before you go down the rabbit hole adding additional Maven dependencies or additional annotations you think might be missing, the reason is usually that the POJO class you are returning doesn’t have any public getter methods. For each property in your POJO that you want returned in your JSON, make sure you have a public getter.

This is discussed in this StackOverflow post here.

Spring Framework Spring Boot

Published at DZone with permission of Kevin Hooke. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook