|
15 | 15 | */
|
16 | 16 | package org.springframework.data.web;
|
17 | 17 |
|
| 18 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
18 | 19 | import com.fasterxml.jackson.databind.JavaType;
|
19 | 20 | import com.fasterxml.jackson.databind.ObjectMapper;
|
20 | 21 | import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
|
21 | 22 | import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
|
| 23 | +import org.reactivestreams.Publisher; |
22 | 24 | import org.springframework.beans.BeansException;
|
23 | 25 | import org.springframework.beans.factory.BeanClassLoaderAware;
|
24 | 26 | import org.springframework.beans.factory.BeanFactory;
|
25 | 27 | import org.springframework.beans.factory.BeanFactoryAware;
|
26 | 28 | import org.springframework.core.ResolvableType;
|
27 | 29 | import org.springframework.core.annotation.AnnotationUtils;
|
| 30 | +import org.springframework.core.codec.DecodingException; |
| 31 | +import org.springframework.core.io.buffer.DataBuffer; |
| 32 | +import org.springframework.core.io.buffer.DataBufferUtils; |
28 | 33 | import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
29 | 34 | import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
30 | 35 | import org.springframework.lang.Nullable;
|
31 | 36 | import org.springframework.util.Assert;
|
32 | 37 | import org.springframework.util.ConcurrentReferenceHashMap;
|
33 | 38 | import org.springframework.util.MimeType;
|
| 39 | +import reactor.core.publisher.Flux; |
| 40 | +import reactor.core.publisher.Mono; |
34 | 41 |
|
| 42 | +import java.math.BigDecimal; |
35 | 43 | import java.util.Map;
|
36 | 44 | import java.util.concurrent.atomic.AtomicReference;
|
37 | 45 |
|
@@ -129,4 +137,33 @@ public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType
|
129 | 137 | }
|
130 | 138 | }
|
131 | 139 |
|
| 140 | + @Override |
| 141 | + public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, |
| 142 | + @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { |
| 143 | + |
| 144 | + ObjectMapper mapper = selectObjectMapper(elementType, mimeType); |
| 145 | + if (mapper == null) { |
| 146 | + throw new IllegalStateException("No ObjectMapper for " + elementType); |
| 147 | + } |
| 148 | + |
| 149 | + Flux<DataBuffer> processed = processInput(input, elementType, mimeType, hints); |
| 150 | + |
| 151 | + return DataBufferUtils.join(processed, this.getMaxInMemorySize()) |
| 152 | + .flatMap(dataBuffer -> Mono.just(decode(dataBuffer, elementType, mimeType, hints))) |
| 153 | + .expand(object -> { |
| 154 | + if (object instanceof Iterable) { |
| 155 | + return Flux.fromIterable((Iterable) object); |
| 156 | + } |
| 157 | + return Flux.just(object); |
| 158 | + }); |
| 159 | + } |
| 160 | + |
| 161 | + @Override |
| 162 | + public Object decode(DataBuffer dataBuffer, ResolvableType targetType, |
| 163 | + @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException { |
| 164 | + |
| 165 | + return projectionFactory.createProjection(ResolvableType.forType(targetType.getType()).resolve(Object.class), |
| 166 | + dataBuffer.asInputStream()); |
| 167 | + } |
| 168 | + |
132 | 169 | }
|
0 commit comments