cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sergey.beryoz...@iona.com>
Subject RE: fromString() not found
Date Thu, 10 Sep 2009 09:36:21 GMT

Hi,

You can also register ParameterHandler, for ex,
CollectionHandler<UnidCollection>, if you do not want to have fromString(),
valueOf(), etc...
http://cxf.apache.org/docs/jax-rs.html#JAX-RS-DealingwithParameters

> why do I need to have the demarshaller when CXF can marshall the
> Collection

I'm presuming you refer to this method :

 public Response addUnids(@QueryParam("userId")String userid,

                              @FormParam("unids")UnidCollection unids) {

            [..]

            return Response.ok().build();

      }

'unids' is referring here to a form field, so it's not JSON at all in this
case, right ?

Or are you referring to the fact no explicit JSON collections (those without
a root element wrapper) can  be deserialized at the moment ? I nealy made it
working the other day, there was some subtle JAXB issue I could not
overcome. I've seen exactly the same issue recently when testing that
collections like List<Book>, where Book.class has no @XmlRootElement, can be
deserialized, so at least I have some reproducible failure pattern to look
at...

cheers, Sergey


Linus Kamb-2 wrote:
> 
> D'oh!  It always works that way. Send off the message right before you
> find
> the obvious.
> 
> I was looking at the final error message, not the stack trace.  In fact
> the
> method was found but had thrown an Exception.  Sorry about that.
> 
> But the ultimate question of why do I need to have the demarshaller when
> CXF
> can marshall the Collection fine still stands.
> 
> Thanks,
> Linus
> 
> 
> -----Message d'origine-----
> De : Linus Kamb [mailto:kamb@emsc-csem.org] 
> Envoyé : Thursday, September 10, 2009 10:40 AM
> À : users@cxf.apache.org
> Objet : fromString() not found
> 
> Hi,
> 
>  
> 
> I am new to CXF, so I apologize if this is obvious and I've missed it in
> the
> docs.
> 
>  
> 
> First, what I am trying to do is POST JSON to a RS service.  And I've made
> that work, although it seems awkward.  I'll get to that.
> 
>  
> 
> I have services defined:
> 
>  
> 
>       // @Produces({"application/json", "text/javascript"})
> 
>       @POST
> 
>       @Path("/add") 
> 
>       public Response addUnids(@QueryParam("userId")String userid,
> 
>                               @FormParam("unids")UnidCollection unids) {
> 
>             [..]
> 
>             return Response.ok().build();
> 
>       }
> 
>       @Produces({"application/json", "text/javascript"})
> 
>       @GET
> 
>       @Path(("/get")
> 
>       public Response getUnids(@QueryParam("userId") String userId) {
> 
>             return Response.ok(buildUnidCollection()).build();
> 
>       }
> 
>  
> 
> The immediate question is:
> 
>  
> 
> I have two classes:  Unid, and UnidCollection.  The latter simply contains
> a
> Collection of the former.
> 
>  
> 
> Both have public static <type> fromString(String str) methods  (as well as
> public static valueOf(String) methods).
> 
>  
> 
> However, when I invoke the service, I get an exception saying the
> UnidOridCollection does not have String constructor, fromString or valueOf
> methods. In fact it has both.    If I add the String constructor to
> UnidCollection, it's happy.  But I'd prefer not to go that route.
> 
>  
> 
> Why does it find the fromString() in Unid, but not in UnidCollection() ?
> 
>  
> 
> The bigger question I have is why is CXF able to automatically marshall to
> JSON, but not the other way around?
> 
> What is it that I need to do to make that automatic (and not need the
> above
> methods)?
> 
>  
> 
> Thanks so much, 
> 
> Linus
> 
>  
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/fromString%28%29-not-found-tp25379507p25380185.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message