Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15467

ServerResponse.BodyBuilder.body(Object) shadows body(Publisher) in Kotlin ServerResponseExtensions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0 RC1
    • Fix Version/s: 5.0 RC1
    • Component/s: Reactive, Web
    • Labels:
    • Last commented by a User:
      false

      Description

      https://jira.spring.io/browse/SPR-15461

      After linked change I am unable to pass Mono<List<String>> to body method.

      The problem is that can't pass generic type of List<String>::class.java to body method.

      Doesn't work:

              val monoList: Mono<List<String>> = Mono.just(listOf("1", "2"))
              ok().contentType(APPLICATION_JSON_UTF8).body(monoList, List<String>::class.java)
      

      Works:

              val flux: Flux<String> = Mono.just(listOf("1", "2")).flatMapIterable { it }
              ok().contentType(APPLICATION_JSON_UTF8).body(flux,  String::class.java)
      

      Code is written in Kotlin , but I think it also applies to Java due to how generics works.
      It is very inconvenient that after linked change we have to provide exact type when we pass Publisher, before that it was not required.

        Issue Links

          Activity

          Hide
          arjen.poutsma Arjen Poutsma added a comment -

          This is specific to Kotlin, as the body(Object) method (unintentionally) overrides the body(Publisher) extension method in ServerResponseExtensions.kt, see here. It does not occur in Java, because there said method requires an extra Class parameter, see here.

          Show
          arjen.poutsma Arjen Poutsma added a comment - This is specific to Kotlin, as the body(Object) method (unintentionally) overrides the body(Publisher) extension method in ServerResponseExtensions.kt , see here . It does not occur in Java, because there said method requires an extra Class parameter, see here .
          Hide
          arjen.poutsma Arjen Poutsma added a comment -
          Show
          arjen.poutsma Arjen Poutsma added a comment - Fixed by renaming body(Object) to syncBody(Object) , see https://github.com/spring-projects/spring-framework/commit/b9dbac7b2cc09f086ce6256744a8a31e5d0fd90e

            People

            • Assignee:
              arjen.poutsma Arjen Poutsma
              Reporter:
              dbacinski Dariusz Bacinski
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                30 weeks, 1 day ago