|
|
|
@ -16,6 +16,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.http.codec.json; |
|
|
|
package org.springframework.http.codec.json; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|
|
|
@ -32,6 +33,7 @@ import reactor.test.StepVerifier; |
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase; |
|
|
|
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase; |
|
|
|
import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.codec.Pojo; |
|
|
|
import org.springframework.http.codec.Pojo; |
|
|
|
import org.springframework.http.codec.ServerSentEvent; |
|
|
|
import org.springframework.http.codec.ServerSentEvent; |
|
|
|
|
|
|
|
|
|
|
|
@ -108,6 +110,26 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa |
|
|
|
.verifyComplete(); |
|
|
|
.verifyComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15727
|
|
|
|
|
|
|
|
public void encodeAsStreamWithCustomStreamingType() throws Exception { |
|
|
|
|
|
|
|
MediaType fooMediaType = new MediaType("application", "foo"); |
|
|
|
|
|
|
|
MediaType barMediaType = new MediaType("application", "bar"); |
|
|
|
|
|
|
|
this.encoder.setStreamingMediaTypes(Arrays.asList(fooMediaType, barMediaType)); |
|
|
|
|
|
|
|
Flux<Pojo> source = Flux.just( |
|
|
|
|
|
|
|
new Pojo("foo", "bar"), |
|
|
|
|
|
|
|
new Pojo("foofoo", "barbar"), |
|
|
|
|
|
|
|
new Pojo("foofoofoo", "barbarbar") |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
ResolvableType type = ResolvableType.forClass(Pojo.class); |
|
|
|
|
|
|
|
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, barMediaType, emptyMap()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(output) |
|
|
|
|
|
|
|
.consumeNextWith(stringConsumer("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")) |
|
|
|
|
|
|
|
.consumeNextWith(stringConsumer("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")) |
|
|
|
|
|
|
|
.consumeNextWith(stringConsumer("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")) |
|
|
|
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void fieldLevelJsonView() throws Exception { |
|
|
|
public void fieldLevelJsonView() throws Exception { |
|
|
|
JacksonViewBean bean = new JacksonViewBean(); |
|
|
|
JacksonViewBean bean = new JacksonViewBean(); |
|
|
|
|