没有消息正文编写器

问题描述 投票:0回答:1

我有一个生成的 JAXB 类(来自 XSD)。我能够以 XML 和 JSON 形式返回,但是一旦我将 text/html 添加到 Produces 注释中,我就会得到:

"No message body writer for response class Employee"

这是我的 API:

@GET
@Path("/employee/{employeeId}/getEmployeeById")
@Produces({"application/xml", "application/json", "text/html"})
public Employee getEmployeeById(@PathParam("employeeId") String employeeId);

这是我的客户调用(使用 CXF 客户端):

WebClient client = WebClient.create(basePath);
    client = client.path("employeeervice/employee/1/getEmployeeById").
    accept(MediaType.TEXT_HTML_TYPE).type(MediaType.TEXT_HTML_TYPE);

客户端响应为500。

调用在 application/xml 中传递的相同 API,它工作正常。

Employee e = client.path("employeeservice/employee/1/getEmployeeById")
    .accept(MediaType.APPLICATION_XML_TYPE).get(Employee.class);

我需要对 text/html 做一些不同的事情吗?

谢谢

cxf jax-rs
1个回答
0
投票

您可以按照此 SO 答案中列出的说明进行操作CXF:找不到类的消息正文编写器 - 自动映射非简单资源 我修改了 text/html 的注释,但它几乎起作用了。还可能想确保您的 POJO 也实现 Serialized。

© www.soinside.com 2019 - 2024. All rights reserved.