Skip to content

JavaTimeModule (jsr 310) LocalDate Deserializer not working with 2.16.0 but works with 2.15.3 #4272

Closed
@captainBlaskowitz

Description

@captainBlaskowitz

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

While upgrading to 2.16.0, getting error while trying to deserialize string to localDate.
It works perfectly fine on 2.15.3.
When trying to POST a json containing a date as string: "28/12/2023", and Deserialize it into a DTO with LocalDate field,
getting an error message:

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from String "28/12/2023": 
Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '28/12/2023' could not be parsed at index 0]

Version Information

2.16.0

Reproduction

maven configuration:

<apache.tomcat.version>10.1.16</apache.tomcat.version>
<spring.version>6.1.2</spring.version>
<spring.data.version>3.2.1</spring.data.version>
<jackson.version>2.16.0</jackson.version>
<hibernate.version>6.4.1.Final</hibernate.version>

<dependencies>
      <dependency>
	      <groupId>com.fasterxml.jackson.core</groupId>
	      <artifactId>jackson-core</artifactId>
	      <version>${jackson.version}</version>
      </dependency>
      
      <dependency>
	      <groupId>com.fasterxml.jackson.core</groupId>
	      <artifactId>jackson-databind</artifactId>
	      <version>${jackson.version}</version>
      </dependency>
      
      <dependency>
	      <groupId>com.fasterxml.jackson.datatype</groupId>
	      <artifactId>jackson-datatype-hibernate6</artifactId>
	      <version>${jackson.version}</version>
      </dependency>
      
      <dependency>
	      <groupId>com.fasterxml.jackson.datatype</groupId>
	      <artifactId>jackson-datatype-jsr310</artifactId>
	      <version>${jackson.version}</version>
      </dependency>
</dependencies>

Jackson ObjectMapper bean configuration:

    @Bean
    ObjectMapper jacksonObjectMapper()
    {
        JavaTimeModule timeModule = new JavaTimeModule();
        timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("dd/MM/yyyy")));

        return new ObjectMapper()
                .registerModule(new Hibernate6Module())
                .registerModule(timeModule);
    }

    @Bean
    MappingJackson2HttpMessageConverter jacksonMessageConverter(ObjectMapper pJacksonObjectMapper)
    {
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        mappingJackson2HttpMessageConverter.setObjectMapper(pJacksonObjectMapper);
        return mappingJackson2HttpMessageConverter;
    }

Controller:

@Controller
@RequestMapping(value = "/")
public class SimpleController
{
   @RequestMapping(value = "/local-date", method = RequestMethod.POST)
    public @ResponseBody String acceptDate
            (
                    @RequestBody @Valid SimipleDTO pSimpleDTO,
                    BindingResult pBindingResult,
                    HttpServletRequest pRequest
            )
    {
        return "ok";
    }
}

DTO:

@Getter
@Setter
public class SimpleDTO
{
    @NotNull
    private LocalDate localDate;
}

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions