Hi Sergey:

Thanks for your reply!
Sorry for the short holiday. I tried your method last week, but I can't get
expected result. 
Following code is the first update, FYI.


@POST
@Consumes("application/www-url-form-encoded")
@Path("/")
public Response addApple(MultivaluedMap<String,String> apple) throws
Exception;


But the eclipse console output a message when I ran it. 

2009-10-19 09:17:12 .No operation matching request path / is found,
ContentType : application/x-www-form-urlencoded;charset=utf-8, Accept :
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,.

I found the issue is happened the ContentType, so I change the ContentType
as same as the request.


@POST
@Consumes("application/x-www-form-urlencoded")
@Path("/")
public Response addApple(MultivaluedMap<String,String> apple) throws
Exception;


And then it still doesn't work whatever I changed or removed the @Consumes
label,  the Exception is javax.xml.bind.MarshalException.

My CXF version is 2.2.3, thanks.


Sergey Beryozkin wrote:
> 
> Hi
> 
> sorry for a late response
> 
> when you do 
> 
> @FormParam("") Apple apple
> 
> then what it means is that all the application/www-url-form-encoded
> sequence is injected (name/value pairs) into an Apple instance.
> 
> So if you'd like to have them all injected into a map then simply do
> 
> @Path("/")
> @Consumes("application/www-url-form-encoded")
> public Response addApple(MultivaluedMap<String,String> apple) {}
> 
> MultivaluedMap should really be used in such cases, as it can hold
> multiple values for a given field key/name; @FormParam can be handy when
> accessing an individual form field value, though @FormParam("") can indeed
> be used to collect them all and inject into the bean.
> 
> cheers, Sergey
> 
> 
> Sam.Wang wrote:
>> 
>> Hello all:
>> 
>> I have a question about parameter mapping. 
>> It works fine when I mapped parameters to customized object. but if I
>> changed the Hashtable or Hashmap, it doesn't work at all. 
>> I searched in google and most results tell me it doesn't support Map type
>> in JAXB, but I have some special reason to do that in using map way.
>> So could everyone can give some suggestions or advices about that?
>> thanks:)
>> 
>> @POST
>>      @Path("/")
>>      public Response addApple(@FormParam("") Apple apple) throws Exception;
>> 
>> I hope it can work when I changed the Apple to Hashtable.
>> 
>> @POST
>>      @Path("/")
>>      public Response addApple(@FormParam("") Hashtable<String,String> apple)
>> throws Exception;
>> passed the  hashtable object is null.
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-map-parameters-to-hashtable-or-hashmap-in-REST.-tp25884722p25952276.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to