Java JAXB父节点和子节点名称相同。子节点返回空值
我使用一个Web服务,收到一个带有同名父节点和子节点的XML响应。问题是最后一个层次结构没有值 在我看来,JAXB应该处理TestDetails列表 班级信封:Java JAXB父节点和子节点名称相同。子节点返回空值,java,xml,web-services,jaxb,Java,Xml,Web Services,Jaxb,我使用一个Web服务,收到一个带有同名父节点和子节点的XML响应。问题是最后一个层次结构没有值 在我看来,JAXB应该处理TestDetails列表 班级信封: @XmlRootElement(name="Envelope", namespace="http://schemas.xmlsoap.org/soap/envelope/") @XmlAccessorType(XmlAccessType.FIELD) public class Envelope { @XmlElement(name=
@XmlRootElement(name="Envelope", namespace="http://schemas.xmlsoap.org/soap/envelope/")
@XmlAccessorType(XmlAccessType.FIELD)
public class Envelope {
@XmlElement(name="Body", namespace="http://schemas.xmlsoap.org/soap/envelope/")
private Body Body;
}
类别团体:
@XmlAccessorType(XmlAccessType.FIELD)
public class Body {
@XmlElement(name="GetTestlistWithConnectionsResponse", namespace="http://tempuri.org/")
private GetTestlistWithConnectionsResponse GetTestlistWithConnectionsResponse;
public Body() {}
}
类GetTestlistWithConnectionsResponse:
@XmlAccessorType(XmlAccessType.FIELD)
public class GetTestlistWithConnectionsResponse {
public GetTestlistWithConnectionsResponse() {}
@XmlElement(name="GetTestlistWithConnectionsResult",
namespace="http://tempuri.org/")
private GetTestlistWithConnectionsResult GetTestlistWithConnectionsResult;
}
类GetTestlistWithConnectionsResult:
@XmlAccessorType(XmlAccessType.FIELD)
public class GetTestlistWithConnectionsResult {
public GetTestlistWithConnectionsResult() {}
@XmlElement(name="TestDetails", namespace="http://schemas.datacontract.org/XXX")
private TestDetails TestDetails ;
}
类测试详细信息:
@XmlAccessorType(XmlAccessType.FIELD)
public class TestDetails{
public TestDetails() {}
@XmlElement(name="A", namespace="http://schemas.datacontract.org/XXX")
private String A;
@XmlElement(name="B", namespace="http://schemas.datacontract.org/XXX")
private String B;
@XmlElement(name="TestDetails")
private List<TestDetails> TestDetails = new ArrayList<TestDetails>();
}
当我调用unmarshall方法时,我接收到一个对象,其中有一个:TestDetails项和一个空列表。我希望列表中包含一个值为A和B的元素。如果没有问题,可以通过更改子元素或子元素名称来尝试。(我认为这是因为标题和子元素的名称相同。)
A.
B
如果没有问题,可以通过更改子元素或子元素名称来尝试。(我认为这是因为标题和子元素的名称相同。)
A.
B
XML中的A
和B
是元素,而不是属性。试着改变
@XmlAttribute
private String A;
private String B;
到
XML中的A
和B
是元素,而不是属性。试着改变
@XmlAttribute
private String A;
private String B;
到
不幸的是,我无法更改XML元素。我必须使用这种结构。不幸的是,我不能更改XML元素。我必须使用这个结构。有什么错误?你能提供一个完整的工作示例吗?您的示例没有命名空间,@XmlRootElement
等。因此很难尝试修复。我没有收到任何错误消息。返回的对象有一个带有空arrayList的TestDetails元素。我本以为列表中有一个元素。现在我提供了一个完整的示例,我忘了在TestDetails.java中引用正确的名称apce。现在它工作了!多谢各位@rwxrwxrwx很好,别忘了发布更新的类作为答案,以帮助未来的访问者。错误是什么?你能提供一个完整的工作示例吗?您的示例没有命名空间,@XmlRootElement
等。因此很难尝试修复。我没有收到任何错误消息。返回的对象有一个带有空arrayList的TestDetails元素。我本以为列表中有一个元素。现在我提供了一个完整的示例,我忘了在TestDetails.java中引用正确的名称apce。现在它工作了!多谢各位@rwxrwxrwx很好,别忘了发布你的更新课程作为回答,以帮助未来的访问者
@XmlAttribute
private String A;
private String B;
@XmlElement(name = "A")
private String a;
@XmlElement(name = "B")
private String b;