That's because Restlet's content negotiation algorithm "prefers" the
'generic' @Get annotation over the more 'specific' @Get(MEDIA_TYPE)
ones.

You'll have to decide which are the representations you plan to return
in the response, which is the 'default' one, and do something like
this (assuming JSON is the desired 'default'):

@Get("json")
public JsonRepresentation toJSON() {
 // Build up and return JSON here
}

@Get("xml")
public XmlRepresentation toXML() {
 // Build up and return XML here
}

// Other @Get(SPECIFIC_MEDIA_TYPE) here without a @Get annotated
method that doesn't specify the media type it will handle back

Hope this helps,

good luck.

On Thu, Mar 31, 2011 at 12:35 PM, Daniele Dellafiore
<[email protected]> wrote:
> I've tried with the @Get
>
>    @Get("json")
>    public JsonRepresentation represent() {
>       return new JsonRepresentation(new JSONArray(find()));
>    }
>
>    public List find() {
>       return getApplication().getSubscriptionService().findTenants();
>    }
>
> without the @Get on the second method, works:
>
> clientResource.get(JsonRepresentation.class);
>
> If I add the annotation, the request arrives to find() method, and fails to
> return a Json.
>
>
> On Wed, Mar 23, 2011 at 11:23 AM, Thierry Boileau
> <[email protected]> wrote:
>>
>> Hello Daniele,
>>
>> >What if the parameter is a Map or a generic POJO?
>> the parameters of the annotation deal with the content negotiation
>> feature, that is to say a choice made according to the media type of the
>> sent entity, the parameter type of the Java method, and the conversion
>> capability of the application (in a few words : the available converters).
>> If the representation of the POJO or MAP is available in JSON format, the
>> @Post("json") methoed will be chosen.
>>
>> > If I remove the annotation from the first method, everything works.
>> > There is a notation to say to the first method he is waiting for a
>> > String class?
>> As there is competition between converters, I guess the default converter
>> should be chosen only if any other available converter does not match (see
>> this RFE http://restlet.tigris.org/issues/show_bug.cgi?id=1093).
>> As a workaround, or as a matter of test, can you test to put the
>> @Post("json") method before the other one in the code of your class?
>>
>> Best regards,
>> Thierry Boileau
>>
>>
>>> that works, I did not think about it, even if it's in the book :)
>>> but is not documented in the API.
>>>
>>> What if the parameter is a Map or a generic POJO?
>>>
>>> On Wed, Mar 23, 2011 at 12:07 AM, Fabian Mandelbaum
>>> <[email protected]> wrote:
>>>>
>>>> Hello Daniele,
>>>>
>>>> @Post("txt")
>>>>
>>>> should accept strings. Test it though ;-)
>>>>
>>>> On Tue, Mar 22, 2011 at 1:07 PM, Daniele Dellafiore <[email protected]>
>>>> wrote:
>>>> > Hi.
>>>> >
>>>> > I built a server resource with a
>>>> >
>>>> >    @Post
>>>> >    public void request(final String email) { ....}
>>>> >
>>>> > that works great with the restlet client. With a real form I have two
>>>> > options: json/xml, say json, or post parameters.
>>>> >
>>>> > Json, I just add
>>>> >
>>>> >    @Post("json")
>>>> >    public void xml(final Representation representation) { ...}
>>>> >
>>>> > in which parse the email from the json and call the request(String
>>>> > email) so
>>>> > I do not duplicate code.
>>>> > There is a problem here: the application/json  post does not end in
>>>> > the
>>>> > @Post("json"), everything falls in the first @Post.
>>>> > If I remove the annotation from the first method, everything works.
>>>> >
>>>> > There is a notation to say to the first method he is waiting for a
>>>> > String
>>>> > class?
>>>> >
>>>> > Thanks.
>>>> > --
>>>> > Daniele Dellafiore
>>>> > http://danieledellafiore.net
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> Fabián Mandelbaum
>>>> IS Engineer
>>>>
>>>> ------------------------------------------------------
>>>>
>>>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2713282
>>>
>>
>
>



-- 
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715672

Reply via email to