【问题标题】:JAXB Unmarshalling Using @XMLJavaTypeAdapters使用 @XMLJavaTypeAdapters 进行 JAXB 解组
【发布时间】:2012-04-23 13:45:04
【问题描述】:

我有三门课

@XmlRootElement
public class GeofenceParameter{

    private GeofenceCenterAddress geofenceCenterAddress;

    private GeofenceCenterCoordinates geofenceCenterCoordinates;
}

public class  GeofenceCenterAddress extends GeofenceParameter{

}

public class  GeofenceCenterCoordinate extends GeofenceParameter{

}

我已经制作了两个不同的 XmlAdapter 扩展类来编组和解组 GeofenceCenterAddress 和 GeofenceCentereCoordinate 中的地理围栏参数

Class forGeofenceCenterCoordinate extends XmlAdapter<ValueType,BoundType>{
}

Class forGeofenceCenterAddress extends XmlAdapter<ValueType,BoundType>{
}

用于根据 Soap 请求发送从 GeofenceParamter 获取与 GeofenceCenterAddress 或 GeofenceCenterCoordinate 类相关的实例。

为此,我在 package-info.java 文件 @XmlJavaTypeAdapters{(@XmlJavaTypeAdapter(type=forGeofenceCenterCoordinate)),@XmlJavaTypeAdapter(type=forGeofenceCenterAddress)} 中使用了注解

但在 Web 服务中,它会给我一个我在注释中指定的类的实例,即来自 GeofenceParamter 的 @XmlJavaTypeAdapter(type=forGeofenceCenterCoordinate) class not of @XmlJavaTypeAdapter(type=forGeofenceCenterAddress)

您能否帮助我在 JAXB 继承编组和解组中获取第二类的实例。

提前致谢

【问题讨论】:

    标签: java jaxb


    【解决方案1】:

    我不记得使用过@XmlJavaTypeAdapters,但@XmlJavaTypeAdapter 注释的正常用法只是@XmlJavaTypeAdapter(forGeofenceCenterCoordinate.class)

    只有在包级别应用注解时才需要类型参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2013-05-30
      • 2014-02-10
      • 2013-11-19
      • 1970-01-01
      • 2013-01-17
      相关资源
      最近更新 更多