Browse Source
This commit replaces Reactive Streams converters for RxJava1 and CompletableFuture with Reactor specific ones. The results in conversion that preserves stream semantics, i.e. Mono vs Flux. For example this is allowed: Flux -> Observable Mono -> Single Mono -> CompletableFuture This is not allowed: Flux -> Single Mono -> Observable Flux -> CompletableFuture As a result it is now possible to check through the ConversionService if a target type to convert to is a stream of many or of one which is useful for decoding purposes. The commit also adds PublisherToFluxConverter to allow conversion from raw Publisher to Flux. The reverse is not necessary since Flux is a Publisher and it's a no-op conversion.pull/1111/head
10 changed files with 108 additions and 48 deletions
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/* |
||||
* Copyright 2002-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.core.convert.support; |
||||
|
||||
import java.util.LinkedHashSet; |
||||
import java.util.Set; |
||||
|
||||
import org.reactivestreams.Publisher; |
||||
import reactor.core.publisher.Flux; |
||||
|
||||
import org.springframework.core.convert.TypeDescriptor; |
||||
import org.springframework.core.convert.converter.GenericConverter; |
||||
|
||||
/** |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
public class PublisherToFluxConverter implements GenericConverter { |
||||
|
||||
@Override |
||||
public Set<ConvertiblePair> getConvertibleTypes() { |
||||
Set<ConvertiblePair> pairs = new LinkedHashSet<>(); |
||||
pairs.add(new ConvertiblePair(Publisher.class, Flux.class)); |
||||
return pairs; |
||||
} |
||||
|
||||
@Override |
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { |
||||
if (source == null) { |
||||
return null; |
||||
} |
||||
else if (Publisher.class.isAssignableFrom(sourceType.getType())) { |
||||
return Flux.from((Publisher)source); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue