是否可以在@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
。
答案 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
一起使用。