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

ResponseEntity<Flux<?>> causes Jackson binding exception [SPR-15478] #20038

Closed
spring-projects-issues opened this issue Apr 25, 2017 · 2 comments
Closed
Assignees
Labels
in: web type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 25, 2017

Dave Syer opened SPR-15478 and commented

@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.


Affects: 5.0 RC1

Referenced from: commits c67b0d6

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 25, 2017

Rossen Stoyanchev commented

I thought I had this fixed, apparently not.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 25, 2017

Rossen Stoyanchev commented

This should be fixed now (build running).

@spring-projects-issues spring-projects-issues added type: bug in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: bug
Projects
None yet
Development

No branches or pull requests

2 participants