spring-data-elasticsearch icon indicating copy to clipboard operation
spring-data-elasticsearch copied to clipboard

Investigate Upgrade to Jackson 3

Open christophstrobl opened this issue 8 months ago • 3 comments

https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0

Related to: spring-projects/spring-data-commons#3292 Due to the amount of breaking changes the upgrade will have a broader impact.

christophstrobl avatar May 16 '25 09:05 christophstrobl

Did a first step (have a branch in my fork):

I had to change the dependencies and imports. Some adjustments where methods that have been renamed (or better the old ones had been deprecated). So far this works, BUT:

I hand a customized ObjectMapper into the JacksonJsonpMapper that is passed into the RestClient from Elasticsearch (the one ES uses by default discards null values, but sending null values to ES is a valid use case). And the JacksonJsonpMapper of course expect a com.fasterxml.jackson.databind.ObjectMapper.

I will need some more investigation how to address that.

sothawo avatar May 24 '25 14:05 sothawo

Looking at https://central.sonatype.com/artifact/co.elastic.clients/elasticsearch-java, the Elasticsearch client 9 references Jackson 2.18.3.

sothawo avatar May 24 '25 14:05 sothawo

ok, as Jackson changed the coordinates and package names, it is possible to use a version 2 ObjectMapper for the Elasticsearch client and version 3 for Spring Data Elasticsearch.

Not sure if this is a good idea, and what consequences this might have for users.

sothawo avatar May 24 '25 15:05 sothawo

For the time being, we support Jackson 2 side by side with Jackson 3 where possible (e.g. by introducing a Jackson 3-based converter/reader variant) favoring Jackson 3 over Jackson 2 where applicable.

I assume that we will have to support this arrangement until the broader ecosystem has fully migrated to Jackson 3.

mp911de avatar Jul 09 '25 08:07 mp911de

Looking at MapDocument, DefaultStringObjectMap, and MappingBuilder I wonder whether we could remove ObjectMapper use from these types at all. toJson() seems a convenience method that is only used in a few specific places (TypeMapper, TypeUtils, RequestConverter).

Would it be possible to switch over to JsonProvider or JsonpMapper JSON processing? In some places (withJson) it seems that we rather use JSON as way to provide settings and let the builders call the methods to bring values into a builder.

mp911de avatar Sep 25 '25 15:09 mp911de

Removing the ObjectMapper from Spring Data Elasticsearch code would definitely mean some bigger rewrite. The MappingBuilder heavily passes the ObjectNodes from that around.

We need mapping from JSON strings to data, both for our users passing in settings, mapping and configuration and for some of the responses.

But how would that change change the fact that we have a dependency to Jackson 2 through Elasticsearch? We need to pass a JsonpMapper into the creation of an ElasticsearchClient, they provide the JacksonJsonpMapper which we currently use and a JsonbJsonpMapper which according to Elasticsearch's code documentation is not efficient as the do some "string representation roundtrips" there.

sothawo avatar Sep 27 '25 17:09 sothawo

The Jackson 3 migration will likely last for a couple of years and probably. I expect that only CVEs and eventually not maintained Jackson 2 will incentivize (or force) the wider ecosystem to migrate to Jackson 3. I don’t want to remove Jackson as dependency, quite the contrary.

Looking through the code, we have quite a few ObjectMapper instances and some areas seem to make use of Jackson more because it is there than because it is necessary. I don’t have the full picture, but that was my impression. I understand that certain functionality has to be JSON and that’s totally fine.

My remarks are more about the design of the aforementioned spots that could benefit from some refinements and to contain the Jackson sprawl (if that makes sense). Am 27. Sept. 2025, 19:30 +0200 schrieb Peter-Josef Meisch @.***>:

sothawo left a comment (spring-projects/spring-data-elasticsearch#3113) Removing the ObjectMapper from Spring Data Elasticsearch code would definitely mean some bigger rewrite. The MappingBuilder heavily passes the ObjectNodes from that around. We need mapping from JSON strings to data, both for our users passing in settings, mapping and configuration and for some of the responses. But how would that change change the fact that we have a dependency to Jackson 2 through Elasticsearch? We need to pass a JsonpMapper into the creation of an ElasticsearchClient, they provide the JacksonJsonpMapper which we currently use and a JsonbJsonpMapper which according to Elasticsearch's code documentation is not efficient as the do some "string representation roundtrips" there. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

mp911de avatar Sep 27 '25 20:09 mp911de

I see that Jackson is starting his upgrade guide.

https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md

youssef3wi avatar Oct 12 '25 15:10 youssef3wi

There is no problem in migrating Spring Data Elasticsearch to Jackson 3, I have that in a branch. But we still have the dependency through elasticsearch-java, which needs Jackson 2.

sothawo avatar Oct 12 '25 16:10 sothawo

we still have the dependency through elasticsearch-java, which needs Jackson 2.

elasticsearch-java-client 9.2.0 added support for Jackson 3.

anbusampath avatar Oct 26 '25 18:10 anbusampath

I upgraded my branch, the current code now is all switched to Jackson3.

I still need to keep Jackson2 as optional runtime dependency, as we only deprecate the use of the Elasticsearch RestClient and do not yet remove it.

Still need to do some tests in my sample test application and adjust some documentation, otherwise this would then be ready to go.

sothawo avatar Oct 27 '25 19:10 sothawo

@sothawo shouldn't this change also need to backport to 6.0 line to avoid Jackson 2 altogether?

anbusampath avatar Nov 24 '25 05:11 anbusampath

First, we cannot yet avoid Jackson 2 altogether at the moment, it is still an optional dependency because users might still use the old RestClient as this is deprecated will be removed later.

Second, this did not make it in the 6.0 branch in time, as it would have needed to have been merged before the release of the last 6.0.0-RC version. We do not add changes between the last RC and GA, only bugfixes. And as for backporting, we only backport bugfixes into released branches.

sothawo avatar Nov 24 '25 09:11 sothawo