Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Spring Exception: MethodArgumentTypeMismatchException

I'm getting and exception that I do not understand. I have a controller, it gives me back a news object and it appears in the Console, so getting the actual news object is not the problem,

@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id) {

    System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + id);

    StatusUpdate status = statusUpdateService.get(id);

    ModelAndView modelAndView = new ModelAndView();
    System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + status);

    modelAndView.getModel().put("status", status);

    modelAndView.setViewName("viewonestatus");

    return modelAndView;
}

.... but when try to execute the JSP it gives me the following error, even with an almost empty JSP, like....

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

hello world

Exception: Exception: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: &#034;viewonestatus&#034;
        Failed URL: http://localhost:8080/viewonestatus/viewonestatus
        Exception message: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: &#034;viewonestatus&#034;

Thanks a lot for your help

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id)

Here you are declaring a path variable named "id" and you declare its type as Long. Nextly you are calling url:

http://localhost:8080/viewonestatus/viewonestatus 

the second "viewonestatus" is obviously not a Long type and this is why spring is throwing an exception because it can't convert "viewonestatus" to Long

your reqeust should look like

http://localhost:8080/viewonestatus/12321
about 4 years ago · Santiago Trujillo Report

0

Well, this was driving me nuts for about 1/2 hour. If you're using SpringBoot, this could help you.

I realized in my controller I was using

@Controller

in stead of

@RestController

That was it. Ugh.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!