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

Spring response handler returning abstract object drops unique fields from concrete class [SPR-13429] #18008

Closed
spring-projects-issues opened this issue Sep 4, 2015 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 4, 2015

Simen Bekkhus opened SPR-13429 and commented

Not really a good title...

We have a @Controller containing a method returning an abstract object (Foo). Another method returns an instance Bar (Bar extends Foo), and this is returned from the request-handler.

The bug is that the fields defined on Bar but not on Foo is dropped during serialization to JSON.

If I return List<Bar> instead of just Bar, it works (all fields are correctly serialized).

A workaround for us now is to return the correct type from the request-handler, manually casting it from Foo to Bar.

Manually calling new ObjectMapper().writeValueAsString on the object in the controller produces the correct JSON, but whatever Spring does to it does not.

Using Jackson 2.6.1

EDIT: Using Spring 4.2.1 fixes the problem. Sorry about the noise!


Affects: 4.2 GA

Issue Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants