I’m writing a REST service using Jersey. I have an abstract class Promotion that has an annotation:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
Thanks to that, when I return a list of objects:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("promotions/")
public List<Promotion> getClosestPromotions() {
List<Promotion> promotions = getPromotions(); //here I get some objects
return promotions;
}
I get a Json string with a “@class” field for every object in that list. But the problem is that if I return a Response:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("promotions/")
public Response getClosestPromotions() {
List<Promotion> promotions = getPromotions(); //here I get some objects
return Response.ok().entity(promotions).build();
}
I’m getting almost the same list, but without additional “@class” field.
Why is that and what can I do to get a list with “@class” field returning a list in Response?
And by the way, surprisingly, it works when I return a Response with one Promotion object only given as an entity and I get that “@class” field.
Maybe you would want to try: