I guess I know what it is, assuming it CXF 2.7.x, JAX-RS 2.0 param converters are complex, you actually need to register ParamConverterProvider

http://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/ext/ParamConverterProvider.html

it will return specific ParamConverters,

example, you may have

@Provider
class ParamConverterProvider implements ParamConverterProvider {

  public ParamConverter getConverter(...) {

       return new TimestampParamConverter();
  }

}

HTH, Sergey

On 04/09/13 15:42, Sergey Beryozkin wrote:
Hi,

What CXF version and how method Date parameter is annotated ?

Cheers, Sergey
On 04/09/13 15:24, eanbiso wrote:
Hi Sergey,
I'm in a similar situation...I must use a parameter converter for Date
type
to be sure at the serialization of a Date parameter the toString() method
adds also the milliseconds info in the produced string (until now I've
seen
that when a Date obj is serialized by default the string is in the format
"Wed Sep 04 16:09:02 CEST 2013" and when I rebuild the Date obj at server
side I lose the ms info).
So I've built a new parameter converter for type Date like this:

@Provider
public class TimestampParamConverter implements ParamConverter<Date> {

    /**
     * Required for REST ws invocation
     */
    @Override
    public Date fromString(String s) {
        //EXAMPLE TEST
        //example s: Mon May 13 14:21:47 CEST 2013
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd
HH:mm:ss
zzz yyyy", Locale.US);
        try {
            return new Date(dateFormat.parse(s).getTime());
        } catch (ParseException e) {
            log.error("Exception building the Date from corresponding
string at REST
ws invocation. We return a NULL object. ",e);
            return null;
        }
    }

    @Override
    public String toString(Date arg0) throws IllegalArgumentException {
        // EXAMPLE TEST
        if(arg0 != null){
            return arg0.toString();
        }else{
            return null;
        }
    }
}

and I've added it on client side loading the endPoint in this way:

    JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();
    proxyFactory.setServiceClass(clazz);
    proxyFactory.setAddress(address);
    List providers = new ArrayList();
    providers.add(new StringArrayBodyReader());
    providers.add(new TimestampParamConverter());
    proxyFactory.setProviders(providers);
    .....

However I'm not able to arrive in the toString() method at the REST API
invocation....
What am I doing wrong?
Thanks a lot,

Andrea



--
View this message in context:
http://cxf.547215.n5.nabble.com/Serialize-parameters-on-client-side-tp5726421p5733516.html

Sent from the cxf-user mailing list archive at Nabble.com.





--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to