Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ val opensearchVersion = "3.5.0-SNAPSHOT"

dependencies {
val jacksonVersion = "2.20.1"
val jackson3Version = "3.0.4"
val jacksonDatabindVersion = "2.20.1"

// Apache 2.0
Expand Down Expand Up @@ -217,6 +218,8 @@ dependencies {
// Apache 2.0
implementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @cthiele42 , I would suggest to have 3.x line as a default for 4.x major release (we should not bring Jackson 2.x and 3.x dependencies at the same time):

Suggested change
implementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
compileOnly ("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
compileOnly ("com.fasterxml.jackson.core", "jackson-databind", jacksonDatabindVersion)

Copy link
Author

@cthiele42 cthiele42 Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need for a certain jackson version in opensearch is driven by the client side. If a client is enforced to use jackson version 2 (by its dependencies), jackson version 2 is needed in opensearch as well for making use of enhanced serialization features.
By making a hard cut towards jackson3 with release 4.x, clients enforced to use jackson2 are effectively locked out.
Therefore I would suggest to support both jackson versions for a while. The jackson library is designed for being used in different major versions in parallel, see: https://github.com/FasterXML/jackson/tree/main?tab=readme-ov-file#jackson-major-versions.

Making Jackson3Mapper the default replacing the Jackson2Mapper default with 4.x is a different thing and I would appreciate it.

Copy link
Collaborator

@reta reta Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two issues to solve here (with 4.x):

  • promote Jackson 3.x
  • optionally, support Jackson 2.x

The clients are free to pick 3.x or 2.x, this is not our decision as you rightly said, but our decision is what the default should be - so most of the clients would work out of the box. We should not depend / bring Jackson 3.x and Jackson 2.x at the same time, hope it makes sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, I missed something here. If 4.x comes with Jackson 3 only, how is the optional support for Jackson2 working in that case?

Copy link
Author

@cthiele42 cthiele42 Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is the misunderstanding: Jackson3 is not backward compatible, it cannot serialize/deserialize Jackson2 objects. So a client side Jackson2 cannot communicate with an opensearch Jackson3, it needs Jackson2 support baked into opensearch.

Copy link
Collaborator

@reta reta Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, I missed something here. If 4.x comes with Jackson 3 only, how is the optional support for Jackson2 working in that case?

It all comes down to JsonProvider impl: add Jackson 2.x deps, exclude Jackson 3.x deps, use JacksonJsonProvider

Perhaps this is the misunderstanding: Jackson3 is not backward compatible, it cannot serialize/deserialize Jackson2 objects.

This is not a concern here I believe

implementation("com.fasterxml.jackson.core", "jackson-databind", jacksonDatabindVersion)
implementation("tools.jackson.core", "jackson-core", jackson3Version)
implementation("tools.jackson.core", "jackson-databind", jackson3Version)
testImplementation("com.fasterxml.jackson.datatype", "jackson-datatype-jakarta-jsonp", jacksonVersion)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needed:

  testImplementation("tools.jackson.datatype", "jackson-datatype-jakarta-jsonp", jackson3Version)


// For AwsSdk2Transport
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.json.jackson;

import jakarta.json.*;
import jakarta.json.spi.JsonProvider;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonGeneratorFactory;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParserFactory;
import tools.jackson.core.JacksonException;
import tools.jackson.core.json.JsonFactory;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Map;

/**
* A partial implementation of JSONP's SPI on top of Jackson.
*/
public class Jackson3JsonProvider extends JsonProvider {

private final JsonFactory jsonFactory;

public Jackson3JsonProvider(JsonFactory jsonFactory) {
this.jsonFactory = jsonFactory;
}

public Jackson3JsonProvider() {
this(new JsonFactory());
}

/**
* Return the underlying Jackson {@link JsonFactory}.
*/
public JsonFactory jacksonJsonFactory() {
return this.jsonFactory;
}

// ---------------------------------------------------------------------------------------------
// Parser

private final ParserFactory defaultParserFactory = new ParserFactory(null);

@Override
public JsonParserFactory createParserFactory(Map<String, ?> config) {
if (config == null || config.isEmpty()) {
return defaultParserFactory;
} else {
// TODO: handle specific configuration
return defaultParserFactory;
}
}

@Override
public JsonParser createParser(Reader reader) {
return defaultParserFactory.createParser(reader);
}

@Override
public JsonParser createParser(InputStream in) {
return defaultParserFactory.createParser(in);
}

private class ParserFactory implements JsonParserFactory {

private final Map<String, ?> config;

ParserFactory(Map<String, ?> config) {
this.config = config == null ? Collections.emptyMap() : config;
}

@Override
public JsonParser createParser(Reader reader) {
try {
return new Jackson3JsonpParser(jsonFactory.createParser(reader));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}
}

@Override
public JsonParser createParser(InputStream in) {
try {
return new Jackson3JsonpParser(jsonFactory.createParser(in));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}
}

@Override
public JsonParser createParser(InputStream in, Charset charset) {
try {
return new Jackson3JsonpParser(jsonFactory.createParser(new InputStreamReader(in, charset)));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}
}

/**
* Not implemented.
*/
@Override
public JsonParser createParser(JsonObject obj) {
return JsonProvider.provider().createParserFactory(null).createParser(obj);
}

/**
* Not implemented.
*/
@Override
public JsonParser createParser(JsonArray array) {
return JsonProvider.provider().createParserFactory(null).createParser(array);
}

/**
* Not implemented.
*/
@Override
public Map<String, ?> getConfigInUse() {
return config;
}
}

// ---------------------------------------------------------------------------------------------
// Generator

private final JsonGeneratorFactory defaultGeneratorFactory = new GeneratorFactory(null);

@Override
public JsonGeneratorFactory createGeneratorFactory(Map<String, ?> config) {
if (config == null || config.isEmpty()) {
return defaultGeneratorFactory;
} else {
// TODO: handle specific configuration
return defaultGeneratorFactory;
}
}

@Override
public JsonGenerator createGenerator(Writer writer) {
return defaultGeneratorFactory.createGenerator(writer);
}

@Override
public JsonGenerator createGenerator(OutputStream out) {
return defaultGeneratorFactory.createGenerator(out);
}

private class GeneratorFactory implements JsonGeneratorFactory {

private final Map<String, ?> config;

GeneratorFactory(Map<String, ?> config) {
this.config = config == null ? Collections.emptyMap() : config;
}

@Override
public JsonGenerator createGenerator(Writer writer) {
try {
return new Jackson3JsonpGenerator(jsonFactory.createGenerator(writer));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}
}

@Override
public JsonGenerator createGenerator(OutputStream out) {
try {
return new Jackson3JsonpGenerator(jsonFactory.createGenerator(out));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}
}

@Override
public JsonGenerator createGenerator(OutputStream out, Charset charset) {
try {
return new Jackson3JsonpGenerator(jsonFactory.createGenerator(new OutputStreamWriter(out, charset)));
} catch (JacksonException je) {
throw Jackson3Utils.convertException(je);
}

}

@Override
public Map<String, ?> getConfigInUse() {
return config;
}
}

// ---------------------------------------------------------------------------------------------
// Unsupported operations

/**
* Not implemented.
*/
@Override
public JsonReader createReader(Reader reader) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonReader createReader(InputStream in) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonWriter createWriter(Writer writer) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonWriter createWriter(OutputStream out) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonWriterFactory createWriterFactory(Map<String, ?> config) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonReaderFactory createReaderFactory(Map<String, ?> config) {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonObjectBuilder createObjectBuilder() {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonArrayBuilder createArrayBuilder() {
throw new UnsupportedOperationException();
}

/**
* Not implemented.
*/
@Override
public JsonBuilderFactory createBuilderFactory(Map<String, ?> config) {
throw new UnsupportedOperationException();
}
}
Loading
Loading