如何告诉 Jersey 使用我的 MessageBodyReader 而不是使用 JAXB?
基本上,我有一些模型都使用 JAXB。但是,我有一些高度自定义的功能可以转换为 JSON 并返回,因此我想编写自己的 MessageBodyReader/Writer 来为我完成这项工作。
现在,写入部分已完成:如果我从 REST 资源返回我的模型之一,它将通过我的编写器。但是,当我尝试接受模型作为 FormParam 时,它不使用我的 MessageBodyReader,而是尝试使用 JAXB 对其进行解组(失败)。
那么我如何告诉 Jersey 使用我的 Reader 呢?
public TestModel testProvider(@FormParam("model") TestModel input){ //doesnt work
return new TestModel(); //this part works!
}
Basically, I have some models which all use JAXB. However, I have some highly custom functionality to convert to JSON and back so I want to write my own MessageBodyReader/Writer to do the job for me.
Right now, the writing portion is done: if i return one of my models from a REST resource, it goes through my writer. But when I try and accept a model as a FormParam, it doesnt use my MessageBodyReader and instead attempts to unmarshal it using JAXB (which fails).
So how I can tell Jersey to use my Reader instead?
public TestModel testProvider(@FormParam("model") TestModel input){ //doesnt work
return new TestModel(); //this part works!
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
<init-param><param-name>com.sun.jersey.config.property.packages</param-name> <param-value> your.package.that.contains.the.provider </param-value> </init-param>
由于您的编写器可以工作,但您的阅读器不能工作,所以我猜您在配置中遗漏了某些内容。需要检查的一些事项:
Since your writer works, but your reader does not, I'm guessing you have just missed something in your configuration. Some things to check: