Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
captainBlaskowitz opened this issue Dec 20, 2023 · 4 comments
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@captainBlaskowitz
Copy link

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

@captainBlaskowitz captainBlaskowitz added the to-evaluate Issue that has been received but not yet evaluated label Dec 20, 2023
@pjfanning
Copy link
Member

pjfanning commented Dec 20, 2023

Please talk to the Spring team. Their code may need to be changed before it works with Jackson 2.16.

You can't just randomly decide to change your jar versions. 2.16 is a minor upgrade not a patch upgrade. It can include some small changes and it is not guaranteed that if you have complicated jar dependencies that you won't have to do some testing and follow up with lib maintainers.

To be clear, we do not accept issues that require non-Jackson libs to test. You need to provide test cases that only use Jackson libs.

@cowtowncoder
Copy link
Member

Pretty sure this is:

FasterXML/jackson-modules-java8#293

reported for 2.16.0, fixed for 2.16.1

@captainBlaskowitz
Copy link
Author

captainBlaskowitz commented Dec 21, 2023

@cowtowncoder thanks for the response.
I just tried to help you guys, not sure why the quite insulting response of your mate was necessary,
especially when from what you sent looks like not connected to spring at all,
good luck

@JooHyukKim
Copy link
Member

Oh no worries @captainBlaskowitz 😆. Please know that efforts to help and contribute to the project are genuinely appreciated. In technical discussions, especially in written form, the tone can sometimes be misinterpreted, and I want to assure you that no offense was intended by anybody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

4 participants