我正在尝试编写以下REST服务。我尝试序列化对象列表并将其发送给客户端。不幸的是,我收到以下错误:
找不到针对媒体类型=应用程序/八位字节流的MessageBodyWriter,类型= org.glassfish.jersey.message.internal.OutboundJaxrsResponse类,genericType = org.glassfish.jersey.message.internal.OutboundJaxrsResponse类。
这是我的休息服务。有人可以告诉我我在做什么错
@GET
@Path ( "/ news")
@Produces (MediaType.APPLICATION_OCTET_STREAM)
Response news () {
List <newsModel> news = dao.getAll ();
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
StreamingOutput stream = null;
try {
ObjectOutputStream oos = new ObjectOutputStream (baos);
oos.writeObject (news);
oos.flush ();
oos.close ();
InputStream is = new ByteArrayInputStream (baos.toByteArray ());
stream = new StreamingOutput () {
@Override
public void write (OutputStream os) throws IOException, WebApplicationException {
int read = 0;
byte [] bytes = new byte [1024];
while ((read = is.read (bytes))! = -1) {
os.write (bytes, 0, read);
}
}
};
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
return Response.ok (stream) .build ();