Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions