|
|
|
@ -34,6 +34,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.ObjectWriter; |
|
|
|
import com.fasterxml.jackson.databind.ObjectWriter; |
|
|
|
import com.fasterxml.jackson.databind.SequenceWriter; |
|
|
|
import com.fasterxml.jackson.databind.SequenceWriter; |
|
|
|
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; |
|
|
|
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ser.FilterProvider; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
@ -48,6 +49,7 @@ import org.springframework.core.io.buffer.DataBufferFactory; |
|
|
|
import org.springframework.core.log.LogFormatUtils; |
|
|
|
import org.springframework.core.log.LogFormatUtils; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.codec.HttpMessageEncoder; |
|
|
|
import org.springframework.http.codec.HttpMessageEncoder; |
|
|
|
|
|
|
|
import org.springframework.http.converter.json.MappingJacksonValue; |
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest; |
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest; |
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse; |
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
@ -148,7 +150,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple |
|
|
|
byte[] separator = getStreamingMediaTypeSeparator(mimeType); |
|
|
|
byte[] separator = getStreamingMediaTypeSeparator(mimeType); |
|
|
|
if (separator != null) { // streaming
|
|
|
|
if (separator != null) { // streaming
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ObjectWriter writer = createObjectWriter(elementType, mimeType, hints); |
|
|
|
ObjectWriter writer = createObjectWriter(elementType, mimeType, null, hints); |
|
|
|
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler()); |
|
|
|
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler()); |
|
|
|
JsonEncoding encoding = getJsonEncoding(mimeType); |
|
|
|
JsonEncoding encoding = getJsonEncoding(mimeType); |
|
|
|
JsonGenerator generator = getObjectMapper().getFactory().createGenerator(byteBuilder, encoding); |
|
|
|
JsonGenerator generator = getObjectMapper().getFactory().createGenerator(byteBuilder, encoding); |
|
|
|
@ -186,7 +188,18 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple |
|
|
|
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, |
|
|
|
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, |
|
|
|
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { |
|
|
|
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { |
|
|
|
|
|
|
|
|
|
|
|
ObjectWriter writer = createObjectWriter(valueType, mimeType, hints); |
|
|
|
Class<?> jsonView = null; |
|
|
|
|
|
|
|
FilterProvider filters = null; |
|
|
|
|
|
|
|
if (value instanceof MappingJacksonValue) { |
|
|
|
|
|
|
|
MappingJacksonValue container = (MappingJacksonValue) value; |
|
|
|
|
|
|
|
value = container.getValue(); |
|
|
|
|
|
|
|
jsonView = container.getSerializationView(); |
|
|
|
|
|
|
|
filters = container.getFilters(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ObjectWriter writer = createObjectWriter(valueType, mimeType, jsonView, hints); |
|
|
|
|
|
|
|
if (filters != null) { |
|
|
|
|
|
|
|
writer = writer.with(filters); |
|
|
|
|
|
|
|
} |
|
|
|
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler()); |
|
|
|
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
JsonEncoding encoding = getJsonEncoding(mimeType); |
|
|
|
JsonEncoding encoding = getJsonEncoding(mimeType); |
|
|
|
@ -268,10 +281,12 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType, |
|
|
|
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType, |
|
|
|
@Nullable Map<String, Object> hints) { |
|
|
|
@Nullable Class<?> jsonView, @Nullable Map<String, Object> hints) { |
|
|
|
|
|
|
|
|
|
|
|
JavaType javaType = getJavaType(valueType.getType(), null); |
|
|
|
JavaType javaType = getJavaType(valueType.getType(), null); |
|
|
|
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null); |
|
|
|
if (jsonView == null && hints != null) { |
|
|
|
|
|
|
|
jsonView = (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT); |
|
|
|
|
|
|
|
} |
|
|
|
ObjectWriter writer = (jsonView != null ? |
|
|
|
ObjectWriter writer = (jsonView != null ? |
|
|
|
getObjectMapper().writerWithView(jsonView) : getObjectMapper().writer()); |
|
|
|
getObjectMapper().writerWithView(jsonView) : getObjectMapper().writer()); |
|
|
|
|
|
|
|
|
|
|
|
|