How does Restlet client handle media type of request?

后端 未结 1 714
慢半拍i
慢半拍i 2021-01-25 03:31

I\'ve got several newbie questions about how Restlet client handles media type header:

  1. What will Restlet client put in \'content-type\' header if I pass in an enti
相关标签:
1条回答
  • 2021-01-25 04:03

    If you rely on the ClientResource class, you can add a MediaType parameter to your put call, such as

    put(myPojo, MediaType.APPLICATION_JSON);
    

    UPDATE Actually, the extra media type parameter defines the accepted result type expected from the remote resource, but doesn't apply to the sent entity.

    The control on the media type of the entity/POJO sent is based on the ConverterService default settings, which depends on the extensions available on your classpath and their respective order.

    You can have full control by directly invoking the

    ClientResource cr = new ClientResource("http://targetDomain/path");
    cr.put(cr.toRepresentation(myPojo, new Variant(MediaType.APPLICATION_JSON));
    

    You also need to add the org.restlet.ext.jackson extension on your classpath and its dependencies. The XStream extension is another option.

    0 讨论(0)
提交回复
热议问题