Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Marshaler#writeJsonToGenerator to allow jackson runtimeOnly dependency #6896

Merged
merged 2 commits into from
Nov 20, 2024
Merged
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
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 {
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
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
Loading