Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATACMNS-1412: Add support for QueryDSL Predicate, Pageable, Sort and ProjectedPayload on WebFlux controllers #2667

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added decode methods
matiasah committed Jul 27, 2022
commit b01b66242dea148f5ea84cf78311e06bcd5ee9c7
Original file line number Diff line number Diff line change
@@ -15,23 +15,31 @@
*/
package org.springframework.data.web;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.reactivestreams.Publisher;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.codec.DecodingException;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.MimeType;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

@@ -129,4 +137,33 @@ public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType
}
}

@Override
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

ObjectMapper mapper = selectObjectMapper(elementType, mimeType);
if (mapper == null) {
throw new IllegalStateException("No ObjectMapper for " + elementType);
}

Flux<DataBuffer> processed = processInput(input, elementType, mimeType, hints);

return DataBufferUtils.join(processed, this.getMaxInMemorySize())
.flatMap(dataBuffer -> Mono.just(decode(dataBuffer, elementType, mimeType, hints)))
.expand(object -> {
if (object instanceof Iterable) {
return Flux.fromIterable((Iterable) object);
}
return Flux.just(object);
});
}

@Override
public Object decode(DataBuffer dataBuffer, ResolvableType targetType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {

return projectionFactory.createProjection(ResolvableType.forType(targetType.getType()).resolve(Object.class),
dataBuffer.asInputStream());
}

}