Skip to content

Commit d89c2e0

Browse files
authored
Remove workaround for CBOR closing streams (#727)
Remove workaround for CBOR closing streams
1 parent d611032 commit d89c2e0

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

changelog/@unreleased/pr-727.v2.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type: improvement
2+
improvement:
3+
description: Remove workaround for CBOR closing streams
4+
links:
5+
- https://github.com/palantir/conjure-java/pull/727
6+
- https://github.com/FasterXML/jackson-dataformats-binary/issues/155

conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/Encodings.java

+2-30
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import com.palantir.logsafe.SafeArg;
2929
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
3030
import com.palantir.logsafe.exceptions.SafeIoException;
31-
import java.io.FilterOutputStream;
3231
import java.io.IOException;
33-
import java.io.OutputStream;
3432

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

7169
@Override
72-
public <T> Serializer<T> serializer(TypeMarker<T> type) {
70+
public final <T> Serializer<T> serializer(TypeMarker<T> type) {
7371
ObjectWriter writer = mapper.writerFor(mapper.constructType(type.getType()));
7472
return (value, output) -> {
7573
Preconditions.checkNotNull(value, "cannot serialize null value");
@@ -78,7 +76,7 @@ public <T> Serializer<T> serializer(TypeMarker<T> type) {
7876
}
7977

8078
@Override
81-
public <T> Deserializer<T> deserializer(TypeMarker<T> type) {
79+
public final <T> Deserializer<T> deserializer(TypeMarker<T> type) {
8280
ObjectReader reader = mapper.readerFor(mapper.constructType(type.getType()));
8381
return input -> {
8482
try {
@@ -134,12 +132,6 @@ public static Encoding cbor() {
134132
public String getContentType() {
135133
return CONTENT_TYPE;
136134
}
137-
138-
@Override
139-
public <T> Serializer<T> serializer(TypeMarker<T> type) {
140-
Serializer<T> delegate = super.serializer(type);
141-
return (value, output) -> delegate.serialize(value, new ShieldingOutputStream(output));
142-
}
143135
};
144136
}
145137

@@ -149,24 +141,4 @@ private static ObjectMapper configure(ObjectMapper mapper) {
149141
// Avoid flushing, allowing us to set content-length if the length is below the buffer size.
150142
.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM);
151143
}
152-
153-
/**
154-
* Work around a CBORGenerator bug. For more information:
155-
* https://github.com/FasterXML/jackson-dataformats-binary/issues/155
156-
*/
157-
private static final class ShieldingOutputStream extends FilterOutputStream {
158-
ShieldingOutputStream(OutputStream out) {
159-
super(out);
160-
}
161-
162-
@Override
163-
public void flush() {
164-
// nop
165-
}
166-
167-
@Override
168-
public void close() {
169-
// nop
170-
}
171-
}
172144
}

0 commit comments

Comments
 (0)