@@ -950,9 +950,9 @@ public void writeValue(JsonGenerator g, Object value)
950
950
{
951
951
_assertNotNull ("g" , g );
952
952
if (_config .isEnabled (SerializationFeature .CLOSE_CLOSEABLE )
953
- && (value instanceof Closeable ))
953
+ && (value instanceof AutoCloseable ))
954
954
{
955
- Closeable toClose = (Closeable ) value ;
955
+ AutoCloseable toClose = (AutoCloseable ) value ;
956
956
try {
957
957
_prefetch .serialize (g , value , _serializationContext ());
958
958
if (_config .isEnabled (SerializationFeature .FLUSH_AFTER_WRITE_VALUE )) {
@@ -966,6 +966,8 @@ public void writeValue(JsonGenerator g, Object value)
966
966
toClose .close ();
967
967
} catch (IOException e ) {
968
968
throw JacksonIOException .construct (e , g );
969
+ } catch (Exception e ) {
970
+ ClassUtil .closeOnFailAndThrowAsJacksonE (g , e );
969
971
}
970
972
} else {
971
973
_prefetch .serialize (g , value , _serializationContext ());
@@ -1101,7 +1103,8 @@ public byte[] writeValueAsBytes(Object value) throws JacksonException
1101
1103
protected final void _configAndWriteValue (SerializationContextExt ctxt ,
1102
1104
JsonGenerator gen , Object value ) throws JacksonException
1103
1105
{
1104
- if (_config .isEnabled (SerializationFeature .CLOSE_CLOSEABLE ) && (value instanceof Closeable )) {
1106
+ if (_config .isEnabled (SerializationFeature .CLOSE_CLOSEABLE )
1107
+ && (value instanceof AutoCloseable )) {
1105
1108
_writeCloseable (gen , value );
1106
1109
return ;
1107
1110
}
@@ -1121,10 +1124,10 @@ protected final void _configAndWriteValue(SerializationContextExt ctxt,
1121
1124
private final void _writeCloseable (JsonGenerator gen , Object value )
1122
1125
throws JacksonException
1123
1126
{
1124
- Closeable toClose = (Closeable ) value ;
1127
+ AutoCloseable toClose = (AutoCloseable ) value ;
1125
1128
try {
1126
1129
_prefetch .serialize (gen , value , _serializationContext ());
1127
- Closeable tmpToClose = toClose ;
1130
+ AutoCloseable tmpToClose = toClose ;
1128
1131
toClose = null ;
1129
1132
tmpToClose .close ();
1130
1133
} catch (Exception e ) {
0 commit comments