How can I tell Jersey to use my MessageBodyReader instead using JAXB?
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!
}
- Mark as @Provider
- Add the configuration to your web.xml EX:
<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:
- Do you have the @Provider annotation on your reader?
- Did you correctly implement the isReadable method on your reader?
- Do you have the appropriate @Consumes annotation on the reader, does its media type match the media type specified on your service method?
精彩评论