我正在尝试解组一个看起来像这样的xml数据包:
<response>
<returncode>SUCCESS</returncode>
<meetings>
<meeting>
<meetingID>test01</meetingID>
<meetingName>Test</meetingName>
<createTime>1315254777880</createTime>
<attendeePW>ap</attendeePW>
<moderatorPW>mp</moderatorPW>
<hasBeenForciblyEnded>false</hasBeenForciblyEnded>
<running>true</running>
</meeting>
</meetings>
</response>
但是,也可以单独请求会议元素
<response>
<returncode>SUCCESS</returncode>
<meetingName>Test</meetingName>
<meetingID>test01</meetingID>
<createTime>1315254777880</createTime>
<voiceBridge>70775</voiceBridge>
<messageKey/>
<message/>
</response>
我想重用一个会议类来实现两种目的:
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class BBBBase {
@XmlElement
private String returncode,messageKey,message;
@XmlRootElement(name="response")
public class BBBMeeting extends BBBBase{
@XmlElement
private String voiceBridge, meetingName, meetingID, attendeePW,moderatorPW;
@XmlRootElement(name="response")
public class BBBMeetings extends BBBBase{
@XmlElementWrapper(name="meetings")
@XmlElement(name="meeting")
private List<BBBMeeting> meetings;
当我将@XmlRootElement留在BBBMeeting上时,解组BBBMeetings会导致异常: java.lang.ClassCastException:nl.project.response.BBBMeeting无法强制转换为nl.project.response.BBBMeetings
当我删除它时,我可以解密BBBMeetings,但我不能再解散BBBMeeting了。
解决方法是创建一个基本BBBMeeting类,其中包含使用@XmlRootElement注释的具体实现类。但这对我来说似乎不太优雅。我认为@XmlElement注释在 私人名单会议; 将覆盖该类的任何类级别注释,但显然它不会。