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

Remove workaround for CBOR closing streams #727

Merged
merged 2 commits into from
Feb 4, 2020
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
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-727.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Remove workaround for CBOR closing streams
links:
- https://github.com/palantir/conjure-java/pull/727
- https://github.com/FasterXML/jackson-dataformats-binary/issues/155
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import com.palantir.logsafe.exceptions.SafeIoException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

// TODO(rfink): Consider async Jackson, see
// https://github.com/spring-projects/spring-framework/commit/31e0e537500c0763a36d3af2570d5c253a374690
Expand Down Expand Up @@ -69,7 +67,7 @@ public final boolean supportsContentType(String contentType) {
}

@Override
public <T> Serializer<T> serializer(TypeMarker<T> type) {
public final <T> Serializer<T> serializer(TypeMarker<T> type) {
ObjectWriter writer = mapper.writerFor(mapper.constructType(type.getType()));
return (value, output) -> {
Preconditions.checkNotNull(value, "cannot serialize null value");
Expand All @@ -78,7 +76,7 @@ public <T> Serializer<T> serializer(TypeMarker<T> type) {
}

@Override
public <T> Deserializer<T> deserializer(TypeMarker<T> type) {
public final <T> Deserializer<T> deserializer(TypeMarker<T> type) {
ObjectReader reader = mapper.readerFor(mapper.constructType(type.getType()));
return input -> {
try {
Expand Down Expand Up @@ -134,12 +132,6 @@ public static Encoding cbor() {
public String getContentType() {
return CONTENT_TYPE;
}

@Override
public <T> Serializer<T> serializer(TypeMarker<T> type) {
Serializer<T> delegate = super.serializer(type);
return (value, output) -> delegate.serialize(value, new ShieldingOutputStream(output));
}
};
}

Expand All @@ -149,24 +141,4 @@ private static ObjectMapper configure(ObjectMapper mapper) {
// Avoid flushing, allowing us to set content-length if the length is below the buffer size.
.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM);
}

/**
* Work around a CBORGenerator bug. For more information:
* https://github.com/FasterXML/jackson-dataformats-binary/issues/155
*/
private static final class ShieldingOutputStream extends FilterOutputStream {
ShieldingOutputStream(OutputStream out) {
super(out);
}

@Override
public void flush() {
// nop
}

@Override
public void close() {
// nop
}
}
}