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

Add application property to customize Jackson default leniency #27547

Closed
mjustin opened this issue Aug 2, 2021 · 2 comments
Closed

Add application property to customize Jackson default leniency #27547

mjustin opened this issue Aug 2, 2021 · 2 comments
Labels
status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@mjustin
Copy link

mjustin commented Aug 2, 2021

Jackson provides a leniency setting for deserialization, which can be configured per property (using @JsonFormat(lenient=OptBoolean.FALSE)) or globally (per ObjectMapper.setDefaultLeniency(false)).

This flag will become more useful as of (the not yet released) Jackson 2.13 per FasterXML/jackson-modules-java8#212, as disabling it will cause Jackson to reject dates with time components (e.g. "2007-12-03T10:15:30", "2007-12-03T10:15:30Z") when deserializing a LocalDate value. Disallowing these time components can be useful, as including them can lead to unintended issues truncating the time part results in the wrong date due to time zone discrepancies between the source & target systems.

In light of this, it would be handy if there were a way to set the default value of this lenient property through a Spring Boot application property.

Workaround

Right now, this property can be configured using a custom Jackson2ObjectMapperBuilderCustomizer bean. Since Spring's Jackson2ObjectMapperBuilder type does not directly expose this property, a post-configurer is probably the simplest way to set this:

@Configuration
public class CustomizedJacksonConfiguration {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer nonLenientObjectMapperBuilderCustomizer() {
        return builder -> builder.postConfigurer(
                objectMapper -> objectMapper.setDefaultLeniency(false));
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 2, 2021
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 9, 2021
@wilkinsona wilkinsona added this to the 2.x milestone Aug 9, 2021
@wilkinsona wilkinsona added the status: ideal-for-contribution An issue that a contributor can help us with label Aug 9, 2021
@lower-case
Copy link
Contributor

Hi @wilkinsona I'm new to project and I'd like to work on this. I've started working on the code, will raise PR shortly.
Thanks!

@snicoll
Copy link
Member

snicoll commented Aug 14, 2021

Closing in favour of PR #27659

@snicoll snicoll closed this as completed Aug 14, 2021
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: ideal-for-contribution An issue that a contributor can help us with labels Aug 14, 2021
@snicoll snicoll removed this from the 2.x milestone Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants