On Sep 14, 2009, at 1:10 AM, imymulla wrote:
>
> Hi,
>
> I am using the Jersey Client at the moment to consume services
> provided by
> tweetmeme. I ran into this problem as tweetmeme respond to all JSON
> format
> requests with text/html instead of application/json. I got around
> this by
> doing the following:
> I use Jackson as my JSON parser/handler/provider
> I extended the JacksonJsonProvider class so that I could support
> text/html
> I add my JsonRootElementProvider class to the ClientConfig
>
Great. Another solution is to develop a ClientFilter that modifies the
Content-Type i.e. changes text/html to application/json.
Paul.
> I can now consume tweetmeme services in XML or JSON format with no
> change to
> my beans or client code. I can provide code if anybody is interested.
>
> Regards,
> Imtiyaz
>
>
> Paul Sandoz wrote:
>>
>> Hi,
>>
>> Arguably the JSON readers/writers could also support text/plain (just
>> like we do for XML).
>>
>> It may be possible to utilize a container request filter which
>> modifies the request to add an appropriate content type based on
>> contents of the entity:
>>
>>
>> https://jersey.dev.java.net/nonav/apidocs/1.1.1-ea/jersey/com/sun/jersey/api/container/filter/package-summary.html
>>
>>
>> Another solution as you indicate is for you to extend from
>> JSONRootElementProvider. Although this class is in the impl package
>> which means that it is not part of the supported API, you could
>> extend
>> it as follows:
>>
>> @Provider
>> @Produces({MediaType.APPLICATION_OCTET_STREAM,
>> MediaType.TEXT_PLAIN})
>> @Consumes({MediaType.APPLICATION_OCTET_STREAM,
>> MediaType.TEXT_PLAIN})
>> public class MyJSONRootElementProvider extends
>> JSONRootElementProvider {
>>
>> public MyJSONRootElementProvider(@Context Providers ps) {
>> super(ps);
>> }
>> }
>>
>>
>> We could move this class and other classes to the API so you can
>> reliable depend on this.
>>
>> Paul.
>>
>>
>> On Aug 14, 2009, at 9:13 AM, Yong Yuan wrote:
>>
>>> Hi,
>>>
>>> Our Jersey-based services need to consume requests from our
>>> clients . Unfortunately, we have no control over what content type
>>> our clients may use. Most of the time our clients may send out
>>> requests in JSON format without specifying any content type, and
>>> sometimes text/plain may be used. In that case, what's the best way
>>> of still supporting JAXB-JSON binding. For example, how can I bind
>>> JSON message to a JavaBean object of type MyDataBean as below?
>>>
>>> @POST
>>> @Consumes({MediaType.APPLICATION_OCTET_STREAM,
>>> MediaType.TEXT_PLAIN})
>>> public Response process(MyDataBean bean){
>>> ....
>>> }
>>>
>>> I thought about creating my own MessageBodyReader implementation,
>>> but that will duplicate logics in JSONRootElementProvider. I won't
>>> be able to extend JSONRootElementProvider either because its
>>> constructors are package-private. Should I use a
>>> JSONRootElementProvider as a delegate to my own MessageBodyReader
>>> implementation? If so, how and where can I grab an instance of
>>> JSONRootElementProvider? Or any better ways?
>>>
>>> Thanks a lot,
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/json-support-for-content-type-other-than-application-json-tp3443407p3638722.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>