resteasy response

2019-03-05 06:13发布

I have a similar case as the one described here: Dynamically change RESTEasy service return type

The problem I'm facing is that I'm trying to return a list of objects (annotated with @XMLRootEntity), but I get a 500 server error code:

The server encountered an internal error (Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/json) that prevented it from fulfilling this request.

Can you give some advice how to solve this issue?

I'm not sure exactly where to look.

Thanks.

1条回答
狗以群分
2楼-- · 2019-03-05 07:05

You should use interface instead of using implementation of list.

Try changing return type with : java.util.List

EDIT: Try to wrap list into GenericEntity :

List<String> myList = new ArrayList<String>();
// add ...
final GenericEntity<List<String>> entity = new GenericEntity<List<String>>(myList) { };
Response.status(Status.BAD_REQUEST).entity(entity).build();
查看更多
登录 后发表回答