Skip to content

Commit 7d74ada

Browse files
authored
Rename Marshaler#writeJsonToGenerator to allow jackson runtimeOnly dependency (#6896)
1 parent 8d6578f commit 7d74ada

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Marshaler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public final void writeJsonTo(OutputStream output) throws IOException {
3232
}
3333

3434
/** Marshals into the {@link JsonGenerator} in proto JSON format. */
35-
public final void writeJsonTo(JsonGenerator output) throws IOException {
35+
// Intentionally not overloading writeJsonTo(OutputStream) in order to avoid compilation
36+
// dependency on jackson when using writeJsonTo(OutputStream). See:
37+
// https://github.com/open-telemetry/opentelemetry-java-contrib/pull/1551#discussion_r1849064365
38+
public final void writeJsonToGenerator(JsonGenerator output) throws IOException {
3639
try (JsonSerializer serializer = new JsonSerializer(output)) {
3740
serializer.writeMessageValue(this);
3841
}

exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/writer/LoggerJsonWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public LoggerJsonWriter(Logger logger, String type) {
3333
public CompletableResultCode write(Marshaler exportRequest) {
3434
SegmentedStringWriter sw = new SegmentedStringWriter(JSON_FACTORY._getBufferRecycler());
3535
try (JsonGenerator gen = JsonUtil.create(sw)) {
36-
exportRequest.writeJsonTo(gen);
36+
exportRequest.writeJsonToGenerator(gen);
3737
} catch (IOException e) {
3838
logger.log(Level.WARNING, "Unable to write OTLP JSON " + type, e);
3939
return CompletableResultCode.ofFailure();

exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/internal/writer/LoggerJsonWriterTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ void testToString() {
3232
@Test
3333
void error() throws IOException {
3434
Marshaler marshaler = mock(Marshaler.class);
35-
Mockito.doThrow(new IOException("test")).when(marshaler).writeJsonTo(any(JsonGenerator.class));
35+
Mockito.doThrow(new IOException("test"))
36+
.when(marshaler)
37+
.writeJsonToGenerator(any(JsonGenerator.class));
3638

3739
Logger logger = Logger.getLogger(LoggerJsonWriter.class.getName());
3840

0 commit comments

Comments
 (0)