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
>>>
>>
>>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715663