0

I have a controller that receives an abstract class. This class has 3 different subclasses.

In order for the controller to receive the ajax call i must add a "@class" : com.my.project.my.Class parameter to the object i'm sending.

This feels really bad to implement. Is there any other ways to send the subclasses and avoiding forcing the client to pass an actual class name with each call.

Thanks

1 Answer 1

1

Jackson has its own inheritance handling mechanism. You don't necessarily need to use @class. See here.

This feature cannot be the cleanest. Jackson does its deserialization through hints from the developer. Notice how you always pass a Class or TypeReference object when interacting with its ObjectMapper. In the same way, the JSON needs to contain hints for which subtype to deserialize to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.