开发者

JAX-RS and JAXB_ENCODING

开发者 https://www.devze.com 2022-12-27 16:00 出处:网络
I am using the RestEasy library to do JAX-RS web services. I am not instantiating a JAXBCon开发者_StackOverflow社区text in my service methods. Is there a way to make JAX-RS include the \"<?xml vers

I am using the RestEasy library to do JAX-RS web services. I am not instantiating a JAXBCon开发者_StackOverflow社区text 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();
}


Add the following annotation to the class:

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

精彩评论

暂无评论...
验证码 换一张
取 消