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

WebFlux can't serialize "Object" return types as response body [SPR-15731] #20287

Closed
spring-projects-issues opened this issue Jul 3, 2017 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 3, 2017

Brian Clozel opened SPR-15731 and commented

Given this WebFlux endpoint:

@RestController
public class TestController {

	@GetMapping("/test")
	public Object myTest() {
		return Mono.just(new User("spring"));
	}
}

Calling that endpoint will result in the following:

java.lang.IllegalArgumentException: Unrecognized Type: org.springframework.core.ResolvableType$EmptyType@6b003199
	at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1222) ~[jackson-databind-2.9.0.pr4.jar:2.9.0.pr4]
	at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:616) ~[jackson-databind-2.9.0.pr4.jar:2.9.0.pr4]
	at org.springframework.http.codec.json.Jackson2CodecSupport.getJavaType(Jackson2CodecSupport.java:89) ~[spring-web-5.0.0.BUILD-20170703.083012-345.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.http.codec.json.Jackson2JsonEncoder.encodeValue(Jackson2JsonEncoder.java:144) ~[spring-web-5.0.0.BUILD-20170703.083012-345.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.http.codec.json.Jackson2JsonEncoder.lambda$encode$0(Jackson2JsonEncoder.java:125) ~[spring-web-5.0.0.BUILD-20170703.083012-345.jar:5.0.0.BUILD-SNAPSHOT]

It seems that the ResponseBodyResultHandler looks at the method return type to get the type information and because this endpoint exposes Object, this leads to an instance of ResolvableType.EmptyType(), which Jackson doesn't know how to deal with.

In those cases, should we derive the type at runtime?
If this is intended behavior, should we forbid Object return types in handlers and perform a hard check at startup?


Affects: 5.0 RC2

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

It does work if the actual type is the POJO to render. I applied a small fix so that the generic type we determine from Mono doesn't end up being ResolvableTypeNone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants