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

ResponseEntity<Flux<?>> causes Jackson binding exception

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0 RC1
    • Fix Version/s: 5.0 RC1
    • Component/s: Reactive
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      	@RequestMapping("/words")
      	public ResponseEntity<Flux<Bar>> words() {
      		return ResponseEntity.ok()
      				.body(Flux.fromArray(new Bar[] { new Bar("foo"), new Bar("bar") }));
      	}
      

      Test:

      	@Test
      	public void words() {
      		assertThat(new TestRestTemplate()
      				.getForObject("http://localhost:" + port + "/words", String.class))
      						.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
      	}
      

      Exception:

      org.junit.ComparisonFailure: expected:<"[[{"value":"foo"},{"value":"bar"}]]"> but was:<"[{"timestamp":1493114601666,"status":500,"error":"Internal Server Error","exception":"org.springframework.http.converter.HttpMessageNotWritableException","message":"Could not write JSON document: Class com.example.Bar not subtype of [simple type, class reactor.core.publisher.Flux<com.example.Bar>] (through reference chain: org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler$CollectedValuesList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Class com.example.Bar not subtype of [simple type, class reactor.core.publisher.Flux<com.example.Bar>] (through reference chain: org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler$CollectedValuesList[0])","path":"/words"}]">
      

      Note that the exception shows up in the response body, not in logs, which is odd.

      If you change the @RequestMapping to just return Flux<Bar> it works fine.

        Attachments

          Activity

            People

            Assignee:
            rstoya05-aop Rossen Stoyanchev
            Reporter:
            david_syer Dave Syer
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

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