JAX-RS NoMessageBodyWriterFoundFailure

后端 未结 2 562
余生分开走
余生分开走 2021-01-25 06:24

the method of my jax-rs application:

@GET
@Produces (MediaType.APPLICATION_JSON)
public List  getDocumentList(@HeaderParam(\"Range\") String head         


        
2条回答
  •  迷失自我
    2021-01-25 06:44

    The snippet below should do the trick.

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getDocumentList(@HeaderParam("Range") String headerRange) {
       int[] range = getRangeFromHeader(headerRange);
       return Response.ok(
            new GenericEntity>( (List)facade.listByRange(range))
             )
             .header("Content-Range", getContentRangeStr(range)).build();
    }
    

    The anonymous GenericEntity subclass is required to supply the correct type information (otherwise erased by the compiler) for the writer.

    -- EDIT

    The reason why your code worked using org.jboss.resteasy.resteasy-jackson-provider but not with org.jboss.resteasy.resteasy-jettison-provider resides on the fundamental difference between the two providers:

    • the former (jackson) relies on a JavaBean model, discovering the properties of the objects to serialize, and needs no type information
    • the latter (jettyson) relies on the JAXB annotations, so it needs the underlying type information, erased by the compiler.

提交回复
热议问题