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
7 changes: 7 additions & 0 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ signing {
dependencies {
val elasticsearchVersion = "9.0.0"
val jacksonVersion = "2.18.3"
val jackson3Version = "3.0.0"
val openTelemetryVersion = "1.32.0"

api(project(":rest5-client"))
Expand Down Expand Up @@ -224,6 +225,11 @@ dependencies {
implementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
implementation("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion)

// Apache 2.0
// https://github.com/FasterXML/jackson
implementation("tools.jackson.core", "jackson-databind", jackson3Version)
implementation("tools.jackson.core", "jackson-core", jackson3Version)

// EPL-2.0 OR BSD-3-Clause
// https://eclipse-ee4j.github.io/yasson/
testImplementation("org.eclipse", "yasson", "3.0.4")
Expand Down Expand Up @@ -306,6 +312,7 @@ class SpdxReporter(val dest: File) : ReportRenderer {
"org.apache.httpcomponents.client5" -> "https://hc.apache.org/"
"org.apache.httpcomponents.core5" -> "https://hc.apache.org/"
"com.fasterxml.jackson" -> "https://github.com/FasterXML/jackson"
"tools.jackson" -> " https://github.com/FasterXML/jackson-bom "
else -> if (info.moduleUrls.isEmpty()) {
throw RuntimeException("No URL found for module '$depName'")
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.
*/

package co.elastic.clients.json.jackson;

import co.elastic.clients.json.JsonBuffer;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpUtils;

import jakarta.json.JsonValue;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.util.TokenBuffer;

import java.io.StringWriter;
import java.lang.reflect.Type;

class Jackson3JsonBuffer implements JsonBuffer, JsonData {
private final TokenBuffer buffer;
private final Jackson3JsonpMapper mapper;

Jackson3JsonBuffer(TokenBuffer buffer, Jackson3JsonpMapper mapper) {
this.buffer = buffer;
this.mapper = mapper;
}

@Override
public JsonParser asParser() {
return new Jackson3JsonpParser(buffer.asParser(), mapper);
}

@Override
public JsonValue toJson() {
try (JsonParser parser = asParser()) {
parser.next(); // move to first event
return parser.getValue();
}
}

@Override
public JsonValue toJson(JsonpMapper mapper) {
// We don't need the mapper
return toJson();
}

@Override
public <T> T to(Type type) {
return to(type, this.mapper);
}

@Override
public <T> T to(Type type, JsonpMapper mapper) {
try (JsonParser parser = asParser()) {
return mapper.deserialize(parser, type);
}
}

@Override
public <T> T deserialize(JsonpDeserializer<T> deserializer) {
return deserialize(deserializer, this.mapper);
}

@Override
public <T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper) {
try (JsonParser parser = asParser()) {
return deserializer.deserialize(parser, mapper);
}
}

@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
if (generator instanceof Jackson3JsonpGenerator) {
Jackson3JsonpGenerator jkGenerator = (Jackson3JsonpGenerator) generator;
try {
buffer.serialize(jkGenerator.jacksonGenerator());
} catch (JacksonException e) {
throw Jackson3Utils.convertException(e);
}
} else {
try (JsonParser parser = asParser()) {
JsonpUtils.copy(parser, generator);
}
}
}

/**
* Renders this buffer as a JSON string for debugger and logging convenience.
*/
@Override
public String toString() {
StringWriter writer = new StringWriter();
try (Jackson3JsonpGenerator generator =
new Jackson3JsonpGenerator(mapper.objectMapper().createGenerator(writer))) {
serialize(generator, mapper);
generator.close();
return writer.toString();
}
}
}
Loading