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

Custom java time module ignored after upgrade to 2.16 #293

Closed
Sjoerd97 opened this issue Dec 4, 2023 · 3 comments
Closed

Custom java time module ignored after upgrade to 2.16 #293

Sjoerd97 opened this issue Dec 4, 2023 · 3 comments

Comments

@Sjoerd97
Copy link

Sjoerd97 commented Dec 4, 2023

Specs
Java 17
Gradle 8
Jackson 2.16

We recently upgraded to jackson 2.16 and we noticed that our custom deserializer is no longer used whenever we register a JsonMapper.
Whenever we downgrade back to 2.15.2 it magically works again.
I tried registering the module after the JsonMapper was build but to no avail

To reproduce you can use this piece of code

`class CustomDateTimeDeserializerTest {

private static final JsonMapper JSON_MAPPER = JsonMapper.builder()
	.addModule(new JavaTimeModule().addDeserializer(LocalDateTime.class, new CustomDateTimeDeserializer()))
	.build();


@Test
void deserializeSummerTime() throws JsonProcessingException {
	LocalDateTimeObject ldtAmsterdam = JSON_MAPPER.readValue("{ \"ldt\": \"2023-04-25T12:39:10Z\" }", LocalDateTimeObject.class);
	assertEquals(LocalDateTime.of(2023, 4, 25, 14, 39, 10), ldtAmsterdam.ldt());
}

}

record LocalDateTimeObject(LocalDateTime ldt) {
}`

Additionally you can create a overriden deserialize method with random logic and put a breakpoint on a certain line in the method. You will come to find out it never reaches the breakpoint

@cowtowncoder
Copy link
Member

Ok this is due to #288 which is fixed for 2.16.1.

The root cause of regression is the fact that the use of JavaTimeModule to add (de)serializers through was not an intended use case -- so that was not tested.
And although I think that is not a good idea to do (adding things to modules you don't control), this appears to be commonly done, so there's a fix.

If you have time and interest, it'd be great to verify that 2.16.1-SNAPSHOT of this module indeed fixes your problem.
I don't yet know when 2.16.1 will be released, but it should be done before end of 2023 (that is within next 4 weeks).

@robobdeijn
Copy link

@Sjoerd97 is currently unavailable, but in his absence I have tested the 2.16.1-SNAPSHOT version and I can confirm that this fixes our issue. Thanks!

@cowtowncoder
Copy link
Member

Thank you @robobdeijn ! Will close as Duplicate; will be resolved by 2.16.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants