saxexception2:在IDREF属性中找到对象,但此对象没有ID

发布于 2025-02-01 18:43:57 字数 2293 浏览 1 评论 0原文

我正在使用Java8的Springboot应用程序,该应用程序是用于在肥皂服务上放置REST接口的代理。结果,我需要将许多POJO转换为生成的肥皂对象,以调用SOAP服务。

这一切都可以很好地工作,但是我有一个生成的类,它给出了错误,因为它没有定义的成员变量(即它是类型object)。

toximityTolocation.java

public class ProximityToLocation extends Locator implements Serializable {
    @XmlElement(
        required = true
    )
    @XmlIDREF
    @XmlSchemaType(
        name = "IDREF"
    )
    protected Object to;

您可以看到生成的proximityTolocation上面的类,它具有object> object> object> object object 的成员变量 代码>。从查看其他肥皂调用对服务的调用中,to对象需要生成类型gpslocator

gpslocator.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
    name = "GPSLocator",
    propOrder = {"latitude", "longitude"}
)
public class GPSLocator extends Locator implements Serializable {
    private static final long serialVersionUID = 1L;
    protected double latitude;
    protected double longitude;

因此,我将设置为对象gpslocator,但是当它试图调用SOAP服务时,它会得到以下错误:

saxexception2:对象 “ com.xxx.transit._2008a.location.gpslocator@6b3cda96” IDREF属性,但此对象没有ID

,我将对象设置为gpslocator,因为这是我所看到的,就像我拦截有效的直接肥皂调用时一样。

解决方案

对我来说似乎to对象需要一个ID,但我不明白如何设置它,因为类不是我的(即我无法更改他们)。

我猜如果gpslocator类具有以下功能:

@XmlID
@XmlElement
public String getId() {
    return id;
}

问题

上面提到的类是由托管SOAP服务的第三部分生成的类,所以我无法修改这些类。

问题

如何将id添加到不是我的生成类?

更多信息

多亏了下面的评论,建议我子类gpslocator class,然后添加id。因此,我尝试了Folloiwng:

public class GPSLocator extends com.xxx.transit._2008a.location.GPSLocator {

    protected String id = Double.toString(Math.random()*1000);

    @XmlID
    @XmlElement
    public String getId() {
        return id;
    }
}

但是,即使使用了此新类,我仍然会遇到相同的错误。

[com.sun.istack.SAXException2: Object "com.xxx.restosgi.dto.transit.location.GPSLocator@6ea818f2" is found in an IDREF property but this object doesnt have an ID.]

我做错了吗?

I am working on a SpringBoot application with Java8 that is a proxy used to put a REST interface on a SOAP service. As a result, I need to convert a number of POJO's to generated SOAP Objects to call the SOAP service.

This all works perfectly, however I have one generated class that is giving an error, because it does not have a defined member variable (i.e. it is of type Object).

ProximityToLocation.java

public class ProximityToLocation extends Locator implements Serializable {
    @XmlElement(
        required = true
    )
    @XmlIDREF
    @XmlSchemaType(
        name = "IDREF"
    )
    protected Object to;

As you can see with the generated ProximityToLocation class above, it has a member variable named to of type Object. I know from looking at other SOAP calls to the service, that the to object needs to be of generated type GPSLocator.

GPSLocator.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
    name = "GPSLocator",
    propOrder = {"latitude", "longitude"}
)
public class GPSLocator extends Locator implements Serializable {
    private static final long serialVersionUID = 1L;
    protected double latitude;
    protected double longitude;

As a result, I set the to object to a GPSLocator, but when it tries to call the SOAP service, it gets the following error:

SAXException2: Object
"com.xxx.transit._2008a.location.GPSLocator@6b3cda96" is found in an
IDREF property but this object doesnt have an ID

I am setting the Object to a GPSLocator because that's what I see being set as when I intercept the direct SOAP calls that are working.

Solution

To me it seems like the to object needs an ID, but I don't understand how to set it because the classes are not mine (i.e. I can't change them).

I guess if the GPSLocator class had the following it would work:

@XmlID
@XmlElement
public String getId() {
    return id;
}

Problem

The classes referred to above a classes that are generated by a third part who hosts the SOAP service, so I cannot modify these classes.

Question

How do I add the id to the generated class that is not mine?

More Info

Thanks to the comments below, it was suggested that I subclass the GPSLocator class and add the id. So I tried the folloiwng:

public class GPSLocator extends com.xxx.transit._2008a.location.GPSLocator {

    protected String id = Double.toString(Math.random()*1000);

    @XmlID
    @XmlElement
    public String getId() {
        return id;
    }
}

However, even if I use this new class, I still get the same error above.

[com.sun.istack.SAXException2: Object "com.xxx.restosgi.dto.transit.location.GPSLocator@6ea818f2" is found in an IDREF property but this object doesnt have an ID.]

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文