Skip to content

Commit dad4a73

Browse files
committed
Consider JsonGenerator.Feature#AUTO_CLOSE_TARGET
1 parent 13e79ed commit dad4a73

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,10 @@ public void close() throws IOException {
330330
flush();
331331
}
332332
finally {
333-
MessagePacker messagePacker = getMessagePacker();
334-
messagePacker.close();
333+
if (isEnabled(Feature.AUTO_CLOSE_TARGET)) {
334+
MessagePacker messagePacker = getMessagePacker();
335+
messagePacker.close();
336+
}
335337
}
336338
}
337339

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.File;
2727
import java.io.FileInputStream;
28+
import java.io.FileOutputStream;
2829
import java.io.IOException;
2930
import java.math.BigDecimal;
3031
import java.util.*;
@@ -263,4 +264,17 @@ public void testBigDecimal() throws IOException {
263264
}
264265
}
265266
}
267+
268+
@Test
269+
public void testDisableFeatureAutoCloseTarget() throws IOException {
270+
File tempFile = File.createTempFile("test", "msgpack");
271+
FileOutputStream out = new FileOutputStream(tempFile);
272+
MessagePackFactory messagePackFactory = new MessagePackFactory();
273+
messagePackFactory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
274+
ObjectMapper objectMapper = new ObjectMapper(messagePackFactory);
275+
List<Integer> integers = Arrays.asList(1);
276+
objectMapper.writeValue(out, integers);
277+
objectMapper.writeValue(out, integers);
278+
out.close();
279+
}
266280
}

0 commit comments

Comments
 (0)