|
17 | 17 | package org.springframework.http.codec.json;
|
18 | 18 |
|
19 | 19 | import java.nio.charset.StandardCharsets;
|
| 20 | +import java.time.Duration; |
20 | 21 | import java.util.Arrays;
|
21 | 22 | import java.util.Collections;
|
22 | 23 | import java.util.Map;
|
23 | 24 |
|
24 | 25 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
25 | 26 | import com.fasterxml.jackson.annotation.JsonTypeName;
|
26 | 27 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 28 | +import com.fasterxml.jackson.databind.SerializationFeature; |
27 | 29 | import org.junit.Test;
|
28 | 30 | import reactor.core.publisher.Flux;
|
29 | 31 | import reactor.core.publisher.Mono;
|
| 32 | +import reactor.test.StepVerifier; |
30 | 33 |
|
31 | 34 | import org.springframework.core.ResolvableType;
|
32 | 35 | import org.springframework.core.codec.AbstractEncoderTestCase;
|
| 36 | +import org.springframework.core.io.buffer.DataBuffer; |
33 | 37 | import org.springframework.core.io.buffer.DataBufferUtils;
|
34 | 38 | import org.springframework.http.MediaType;
|
35 | 39 | import org.springframework.http.codec.Pojo;
|
36 | 40 | import org.springframework.http.codec.ServerSentEvent;
|
37 | 41 | import org.springframework.util.MimeType;
|
| 42 | +import org.springframework.util.MimeTypeUtils; |
38 | 43 |
|
39 | 44 | import static java.util.Collections.singletonMap;
|
40 | 45 | import static org.junit.Assert.*;
|
@@ -85,8 +90,6 @@ public void encode() throws Exception {
|
85 | 90 | .consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n"))
|
86 | 91 | .verifyComplete(),
|
87 | 92 | APPLICATION_STREAM_JSON, null);
|
88 |
| - |
89 |
| - |
90 | 93 | }
|
91 | 94 |
|
92 | 95 | @Test // SPR-15866
|
@@ -200,6 +203,21 @@ public void classLevelJsonView() {
|
200 | 203 | null, hints);
|
201 | 204 | }
|
202 | 205 |
|
| 206 | + @Test // gh-22771 |
| 207 | + public void encodeWithFlushAfterWriteOff() { |
| 208 | + ObjectMapper mapper = new ObjectMapper(); |
| 209 | + mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false); |
| 210 | + Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(mapper); |
| 211 | + |
| 212 | + Flux<DataBuffer> result = encoder.encode(Flux.just(new Pojo("foo", "bar")), this.bufferFactory, |
| 213 | + ResolvableType.forClass(Pojo.class), MimeTypeUtils.APPLICATION_JSON, Collections.emptyMap()); |
| 214 | + |
| 215 | + StepVerifier.create(result) |
| 216 | + .consumeNextWith(expectString("[{\"foo\":\"foo\",\"bar\":\"bar\"}]")) |
| 217 | + .expectComplete() |
| 218 | + .verify(Duration.ofSeconds(5)); |
| 219 | + } |
| 220 | + |
203 | 221 |
|
204 | 222 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
205 | 223 | private static class ParentClass {
|
|
0 commit comments