|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2016, 2024 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2025 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made available under the
|
5 | 5 | * terms of the Eclipse Public License v. 2.0 which is available at
|
|
12 | 12 |
|
13 | 13 | package org.eclipse.yasson.internal;
|
14 | 14 |
|
| 15 | +import java.io.FilterWriter; |
15 | 16 | import java.io.InputStream;
|
16 | 17 | import java.io.OutputStream;
|
17 | 18 | import java.io.Reader;
|
@@ -145,15 +146,15 @@ public String toJson(Object object, Type type) throws JsonbException {
|
145 | 146 | @Override
|
146 | 147 | public void toJson(Object object, Writer writer) throws JsonbException {
|
147 | 148 | final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext);
|
148 |
| - try (JsonGenerator generator = writerGenerator(writer)) { |
| 149 | + try (JsonGenerator generator = writerGenerator(new CloseSuppressingWriter(writer))) { |
149 | 150 | marshaller.marshallWithoutClose(object, generator);
|
150 | 151 | }
|
151 | 152 | }
|
152 | 153 |
|
153 | 154 | @Override
|
154 | 155 | public void toJson(Object object, Type type, Writer writer) throws JsonbException {
|
155 | 156 | final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext, type);
|
156 |
| - try (JsonGenerator generator = writerGenerator(writer)) { |
| 157 | + try (JsonGenerator generator = writerGenerator(new CloseSuppressingWriter(writer))) { |
157 | 158 | marshaller.marshallWithoutClose(object, generator);
|
158 | 159 | }
|
159 | 160 | }
|
@@ -234,4 +235,17 @@ public void close() throws Exception {
|
234 | 235 | jsonbContext.getComponentInstanceCreator().close();
|
235 | 236 | }
|
236 | 237 |
|
| 238 | + private static class CloseSuppressingWriter extends FilterWriter { |
| 239 | + |
| 240 | + protected CloseSuppressingWriter(final Writer in) { |
| 241 | + super(in); |
| 242 | + } |
| 243 | + |
| 244 | + @Override |
| 245 | + public void close() { |
| 246 | + // do not close |
| 247 | + } |
| 248 | + |
| 249 | + } |
| 250 | + |
237 | 251 | }
|
0 commit comments