我对所见的XML输出感到困惑 . 下面我有两个扩展同一父级的子类 . 当使用REST在浏览器中编组并查看为XML时,Child类1(GeoLocationDecodedPayload)始终具有geoLocationDecodedPayload的根元素 . 由于某种原因,子类2(AltitudeDecodedPayload) doesn't 将altitudeDecodedPayload作为其根元素,这是其在@XMLRootElement注释中指定的意外情况 . XML输出显示geoPayload的超类(GeoPayload)@XMLRootElement . 任何想法为什么这两个类的行为不同?
child class 1:
package com.api.model.vo.decoder;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.api.util.decoder.DecoderConstants;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "geoLocationDecodedPayload")
public class GeoLocationDecodedPayload extends GeoPayload implements Serializable {
public GeoLocationDecodedPayload() {}
}
child class 2:
package com.api.model.vo.decoder;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.api.util.decoder.DecoderConstants;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "altitudeDecodedPayload")
public class AltitudeDecodedPayload extends GeoPayload implements Serializable {
public AltitudeDecodedPayload() {}
}
parent class:
package com.api.model.vo.decoder;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "geoPayload")
public class GeoPayload {
public GeoPayload() {}
}
1 回答
我忘了在下面包含AltitudeDecodedPayload.class . 这解决了我的问题 .