JAX-RS 和 JAXB_ENCODING

发布于 2024-08-29 02:55:26 字数 904 浏览 9 评论 0原文

我正在使用 RestEasy 库来执行 JAX-RS Web 服务。我没有在我的服务方法中实例化 JAXBContext。有没有办法让 JAX-RS 包含“”它返回的 XML 中的标头字符串?这是我的代码中的示例服务方法:

@GET
@Path("/patients/{patient_id}/diagnoses/portal_edits")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDiagnosisPortalEdits(@Context final UriInfo info,
                                        @PathParam("practice_id") final int practiceId,
                                        @PathParam("patient_id") final long patientId) {
    logger.info(SERVICE_NAME + ".getDiagnosisPortalEdits: " + info.getPath());

    final DiagnosisPortalEdits diagnosisPortalEdits = new DiagnosisPortalEdits();

    diagnosisPortalEdits.getDiagnosisPortalEdits().addAll(DefaultDiagnosisPortalEditService.doLoadForPatientId(practiceId,
            patientId));
    return Response.ok(diagnosisPortalEdits).build();
}

I am using the RestEasy library to do JAX-RS web services. I am not instantiating a JAXBContext in my service methods. Is there a way to make JAX-RS include the "<?xml version...?>" header string in the XML it returns? Here is a sample service method from my code:

@GET
@Path("/patients/{patient_id}/diagnoses/portal_edits")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDiagnosisPortalEdits(@Context final UriInfo info,
                                        @PathParam("practice_id") final int practiceId,
                                        @PathParam("patient_id") final long patientId) {
    logger.info(SERVICE_NAME + ".getDiagnosisPortalEdits: " + info.getPath());

    final DiagnosisPortalEdits diagnosisPortalEdits = new DiagnosisPortalEdits();

    diagnosisPortalEdits.getDiagnosisPortalEdits().addAll(DefaultDiagnosisPortalEditService.doLoadForPatientId(practiceId,
            patientId));
    return Response.ok(diagnosisPortalEdits).build();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2024-09-05 02:55:26

将以下注释添加到类中:

@XmlHeader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")

Add the following annotation to the class:

@XmlHeader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文