如何在JAXB中解组工作? [英] How does unmarshalling work in JAXB?

查看:68
本文介绍了如何在JAXB中解组工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jaxb中有一个元素的getter / setter对:

I have a getter/setter pair for an element in jaxb:

@XmlElementWrapper(name="requires", required=true) 
@XmlElement(name="equals", required=true)
List<MyObject> getMyObjects() {
    return this.myObject;
}
void setMyObjects(final MyObject... myObjects) {
    //call the regular method for setting the objects 
    //that does not have the required signature type
}

问题是setter方法永远不会被调用。我在getter和setter都设置了一个断点,并且getter的一个断点被击中,但不是setter的。

The thing is that the setter method is never getting called. I put a breakpoint on both the getter and setter, and the one by the getter is hit, but not the setter's.

我刚发现这个问题,但我不完全理解答案。 myObjects 在构造时被初始化,所以看起来它适合场景2.在调用getter之后的解组过程中会发生什么?

I just found this question, but I don't fully understand the answer. myObjects is initialized at construction time, so it looks like it fits into Scenario 2. What happens in the unmarshalling process after the getter is called?

推荐答案

您的setter与您的getter的签名不匹配。而不是:

Your setter doesn't match up with the signature of your getter. Instead of:

void setMyObjects(final MyObject... myObjects)

您需要

void setMyObjects(List <MyObject> myObjects)

这篇关于如何在JAXB中解组工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆