我有一个WS,它的接口和实现如下:
@WebService
public interface MyApi{
@WebMethod
public @XmlElement MyResponse myMethod(
@WebParam(name = "myParam") @XmlElement(required = true) PersonId personId);
}
还有PersonId
,它允许选择几种ID方法之一。
@XmlType(name = "personId")
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class IdPaciente implements Serializable {
private static final long serialVersionUID = 1L;
private Passport passport;
private DrivingLicence drivingLicence;
@XmlElements(
{
@XmlElement(name = "passport", type = Passport.class),
@XmlElement(name = "drivingLicence", type = DrivingLicence.class)
})
public Object getId() {
return this.passport != null ? this.passport : this.drivingLicence;
}
...
}
这些Passport
和DrivingLicence
Bean中的每个仅具有一个具有代码值的String属性:
@XmlType(name="passport")
public class CipAutonomico implements Serializable {
private static final long serialVersionUID = 1L;
private String passportSerial;
@XmlElement(required = true)
public String getPassportSerial() {
return this.passportSerial;
}
...
}
现在,它可以工作,但是这也意味着我以太冗长的XML结尾:
<myParam>
<passport>
<passportSerial>1234</passportSerial>
</myParam>
</myParam>
因此,我创建了一个XmlAdapter
,可以将整个Passport
bean直接转换为带有序列号的String:
public class PassportAdapter extends XmlAdapter<String, Passport>{
@Override
public Passport unmarshal(String v) throws Exception {
System.out.println("Unmarshal " + v);
if (v == null) {
return null;
}
Passport passport = new Passport();
passport.setPassportSerial(v);
return passport;
}
@Override
public String marshal(Passport v) throws Exception {
System.out.println("Marshal " + v);
if (v == null) {
return null;
}
return v.getPassportSerial();
}
}
但是,当WS部署并运行时,WSDL尚未更改,并且未调用适配器。
我注释了Passport
:
@XmlType(name="passport")
@XmlJavaTypeAdapter(value = PassportAdapter.class)
public class Passport implements Serializable {
然后我在package-info
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters({
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(
type = es.ssib.otic.test.apiCitasWar.ejbCitas.beans.CipAutonomico.class,
value = es.ssib.otic.test.apiCitasWar.ejbCitas.beans.adapters.CipAutonomicoAdapter.class)
})
package mypackage;
我想念什么?
我正在JDK 8上使用WildFly 14.0.1.Final