将枚举作为@WebParam传递?

时间:2014-08-21 07:18:44

标签: java web-services soap jaxb jax-ws

是否可以在@WebParam网络服务中将枚举作为SOAP传递?

@XmlEnum
public enum TestEnum {
   TEST;
}

@WebService
public class WebService {
   @WebMethod
   public void test(@WebParam TestEnum test) {
       Sysout(test);
   }
}

至少如果我这样做并使用soapUI <test>test</test>进行测试,则打印输出始终为null

2 个答案:

答案 0 :(得分:1)

从String到枚举类的默认映射将使用枚举名称(),它将区分大小写,因此您应该使用<test>TEST</test>

答案 1 :(得分:0)

我发现,对于复杂的枚举映射,还可以按如下方式引入xml适配器:

public class EnumAdapter extends XmlAdapter<String, TestEnum> {

    @Override
    public TestEnum unmarshal(String value) throws Exception {
        return TestEnum.fromValue(value);
    }

    @Override
    public String marshal(TestEnum value) throws Exception {
        return value.toString();
    }
}

@XmlJavaTypeAdapter(EnumAdapter.class)参数上的@WebMethod一起使用。