JAX-WS和Joda-Time? [英] JAX-WS and Joda-Time?

查看:132
本文介绍了JAX-WS和Joda-Time?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写JAX-WS服务,以便@WebMethod的@WebParam是像DateTime这样的Joda-Time类?参数上的@XmlTypeAdapter会起作用吗?我正在部署到GlassFish 2.1。

How do I write a JAX-WS service so the @WebParam of my @WebMethod is a Joda-Time class like DateTime? Will @XmlTypeAdapter on a parameter work? I'm deploying to GlassFish 2.1.

让我澄清这个问题,因为到目前为止这两个答案都集中在将自定义类型绑定到现有的JAXB类上,这些类是相关的但不是我问的问题。如何使以下@WebService接受joda DateTime对象作为参数?

Let me clarify the question because both answers so far have focused on binding custom types to existing JAXB classes, which is related but not the question I'm asking. How do I make the following @WebService accept joda DateTime objects as parameters?

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import org.joda.time.DateTime;

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface Resender {
    @WebMethod
    void resend(
            @WebParam(name = "start") DateTime start,
            @WebParam(name = "end") DateTime end
    );

}


推荐答案

你有直接注释参数如下(我正在使用@DennisTemper编写的XSDDateTimeMarshaller作为你问题的答案之一,但可以用另一个替换...):

You have to annotate the parameter directly such as below (I am making use of XSDDateTimeMarshaller written by @DennisTemper as one of the answers to your question but feel free to substitute with another one...) :

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface Resender {
    @WebMethod
    void resend(
        @WebParam(name = "start") @XmlJavaTypeAdapter(type = DateTime.class, value = XSDDateTimeMarshaller.class) DateTime start,
        @WebParam(name = "end") @XmlJavaTypeAdapter(type = DateTime.class, value = XSDDateTimeMarshaller.class) DateTime end
    );
}

这篇关于JAX-WS和Joda-Time?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆