org.springframework.core

Class ReactiveAdapter

  • java.lang.Object
    • org.springframework.core.ReactiveAdapter


  • public class ReactiveAdapter
    extends java.lang.Object
    Adapter for a Reactive Streams Publisher to and from an async/reactive type such as CompletableFuture, RxJava Observable, and others.

    An adapter is typically obtained via ReactiveAdapterRegistry.

    Since:
    5.0
    Author:
    Rossen Stoyanchev
    • Constructor Summary

      Constructors 
      Constructor and Description
      ReactiveAdapter(ReactiveTypeDescriptor descriptor, java.util.function.Function<java.lang.Object,org.reactivestreams.Publisher<?>> toPublisherFunction, java.util.function.Function<org.reactivestreams.Publisher<?>,java.lang.Object> fromPublisherFunction)
      Constructor for an adapter with functions to convert the target reactive or async type to and from a Reactive Streams Publisher.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.Object fromPublisher(org.reactivestreams.Publisher<?> publisher)
      Adapt from the given Reactive Streams Publisher.
      ReactiveTypeDescriptor getDescriptor()
      Return the descriptor of the reactive type for the adapter.
      java.lang.Class<?> getReactiveType()
      Shortcut for getDescriptor().getReactiveType().
      boolean isMultiValue()
      Shortcut for getDescriptor().isMultiValue().
      boolean isNoValue()
      Shortcut for getDescriptor().isNoValue().
      boolean supportsEmpty()
      Shortcut for getDescriptor().supportsEmpty().
      <T> org.reactivestreams.Publisher<T> toPublisher(java.lang.Object source)
      Adapt the given instance to a Reactive Streams Publisher.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReactiveAdapter

        public ReactiveAdapter(ReactiveTypeDescriptor descriptor,
                               java.util.function.Function<java.lang.Object,org.reactivestreams.Publisher<?>> toPublisherFunction,
                               java.util.function.Function<org.reactivestreams.Publisher<?>,java.lang.Object> fromPublisherFunction)
        Constructor for an adapter with functions to convert the target reactive or async type to and from a Reactive Streams Publisher.
        Parameters:
        descriptor - the reactive type descriptor
        toPublisherFunction - adapter to a Publisher
        fromPublisherFunction - adapter from a Publisher
    • Method Detail

      • getDescriptor

        public ReactiveTypeDescriptor getDescriptor()
        Return the descriptor of the reactive type for the adapter.
      • getReactiveType

        public java.lang.Class<?> getReactiveType()
        Shortcut for getDescriptor().getReactiveType().
      • isMultiValue

        public boolean isMultiValue()
        Shortcut for getDescriptor().isMultiValue().
      • supportsEmpty

        public boolean supportsEmpty()
        Shortcut for getDescriptor().supportsEmpty().
      • isNoValue

        public boolean isNoValue()
        Shortcut for getDescriptor().isNoValue().
      • toPublisher

        public <T> org.reactivestreams.Publisher<T> toPublisher(@Nullable
                                                                java.lang.Object source)
        Adapt the given instance to a Reactive Streams Publisher.
        Parameters:
        source - the source object to adapt from; if the given object is null, ReactiveTypeDescriptor.getEmptyValue() is used.
        Returns:
        the Publisher representing the adaptation
      • fromPublisher

        public java.lang.Object fromPublisher(org.reactivestreams.Publisher<?> publisher)
        Adapt from the given Reactive Streams Publisher.
        Parameters:
        publisher - the publisher to adapt from
        Returns:
        the reactive type instance representing the adapted publisher