Coding⏱️ 3 min read📅 2026-05-31

How to Fix: How to use LocalDateTime RequestParam in Spring? I get "Failed to convert String to LocalDateTime"

Use @DateTimeFormat to specify the format of your LocalDateTime parameter.

Quick Answer: Add @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) to your @RequestParam annotation to correctly parse the date/time string.

The error 'Failed to convert String to LocalDateTime' in Spring Boot occurs when the Jackson library is unable to parse a string into a Java 8 Date/Time object. This can happen if the date format used in the RequestParam annotation does not match the format of the data being sent in the HTTP request.

🛑 Root Causes of the Error

  • The date format used in the RequestParam annotation does not match the format of the data being sent in the HTTP request.

✅ Best Solutions to Fix It

Method 1: Use a Custom Date Format

  1. Step 1: Add the following configuration to your application.properties file:
<bean class="org.springframework.boot.autoconfigure.web.servlet.WebMvcConfigurer"> <bean class="org.springframework.http.server.server.HttpServerHttpRequestHandler"/> <setRequestHeaderMapper> org.springframework.http.server.server.HttpServerHttpRequestHeaderMapper </setRequestHeaderMapper> </bean>

This configuration tells Jackson to use a custom date format for the LocalDateTime type.

Method 2: Use @DateTimeFormat with Iso

  1. Step 1: Update the @RequestParam annotation to use the @DateTimeFormat annotation with the iso format:
@GetMapping("/test") public Page<User> get( @RequestParam(value = "start", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime start) { //... }

This configuration tells Jackson to use the ISO date format for the LocalDateTime type.

🎯 Final Words

By following these methods, you should be able to fix the 'Failed to convert String to LocalDateTime' error in your Spring Boot application.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions