Skip to content

Commit

Permalink
Rename Marshaler#writeJsonToGenerator to allow jackson runtimeOnly de…
Browse files Browse the repository at this point in the history
…pendency (#6896)
  • Loading branch information
jack-berg authored Nov 20, 2024
1 parent 8d6578f commit 7d74ada
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public final void writeJsonTo(OutputStream output) throws IOException {
}

/** Marshals into the {@link JsonGenerator} in proto JSON format. */
public final void writeJsonTo(JsonGenerator output) throws IOException {
// Intentionally not overloading writeJsonTo(OutputStream) in order to avoid compilation
// dependency on jackson when using writeJsonTo(OutputStream). See:
// https://github.com/open-telemetry/opentelemetry-java-contrib/pull/1551#discussion_r1849064365
public final void writeJsonToGenerator(JsonGenerator output) throws IOException {
try (JsonSerializer serializer = new JsonSerializer(output)) {
serializer.writeMessageValue(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LoggerJsonWriter(Logger logger, String type) {
public CompletableResultCode write(Marshaler exportRequest) {
SegmentedStringWriter sw = new SegmentedStringWriter(JSON_FACTORY._getBufferRecycler());
try (JsonGenerator gen = JsonUtil.create(sw)) {
exportRequest.writeJsonTo(gen);
exportRequest.writeJsonToGenerator(gen);
} catch (IOException e) {
logger.log(Level.WARNING, "Unable to write OTLP JSON " + type, e);
return CompletableResultCode.ofFailure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void testToString() {
@Test
void error() throws IOException {
Marshaler marshaler = mock(Marshaler.class);
Mockito.doThrow(new IOException("test")).when(marshaler).writeJsonTo(any(JsonGenerator.class));
Mockito.doThrow(new IOException("test"))
.when(marshaler)
.writeJsonToGenerator(any(JsonGenerator.class));

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

Expand Down

0 comments on commit 7d74ada

Please sign in to comment.