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

查看:22
本文介绍了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天全站免登陆