【问题标题】:Accessing the Jersey resource object in a MessageBodyReader/Writer在 MessageBodyReader/Writer 中访问 Jersey 资源对象
【发布时间】:2014-07-24 12:07:26
【问题描述】:

我在泽西岛有以下资源:

@Path("/my-resource")
@Produces("application/xml")
public class MyResource {

    @Path("/result")
    public MyResponse result() {
        return new MyResponse();
    }

}

我现在想编写一个 MessageBodyReader/Writer,它使用不同的方法来序列化/反序列化 MyResponse 对象,具体取决于用于创建响应的 MyResource 的属性(计划是为不同的 API 版本提供两个 MyResource 实例,并且以不同的方式对它们进行序列化)。

现在的问题是如何访问处理 Jersey 中请求的 MyResource 实例?任何帮助将不胜感激。

问候, 乔辰

【问题讨论】:

    标签: jersey jax-ws


    【解决方案1】:

    您不需要访问MyResource,只需为您的MyResponse 类实现MessageBodyReader / MessageBodyWriter 并将它们注册到您的ObjectMapper 实例。

    如果您不知道如何访问您的ObjectMapper,请查找ContextResolver<ObjectMapper>

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      相关资源
      最近更新 更多