Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAXB解组器对于嵌套对象始终具有空值_Java_Xml_Web Services_Jaxb_Unmarshalling - Fatal编程技术网

Java JAXB解组器对于嵌套对象始终具有空值

Java JAXB解组器对于嵌套对象始终具有空值,java,xml,web-services,jaxb,unmarshalling,Java,Xml,Web Services,Jaxb,Unmarshalling,我有一个web服务,它是通过编写WSDL和底层XSD定义的,java服务器代码类/java绑定是使用JAXB/xjc生成的 一切看起来都很好,服务运行正常。。。但是对于每一个请求(当查看日志输出时,在接收后看起来格式良好),当通过java代码访问时,嵌套元素似乎总是空的 有人能理解为什么customerId.getCustomer()总是返回null吗 我的XSD(部分): 生成的类CustomerId: @xmlacessortype(xmlacesstype.FIELD) @XmlTyp

我有一个web服务,它是通过编写WSDL和底层XSD定义的,java服务器代码类/java绑定是使用JAXB/xjc生成的

一切看起来都很好,服务运行正常。。。但是对于每一个请求(当查看日志输出时,在接收后看起来格式良好),当通过java代码访问时,嵌套元素似乎总是空的

有人能理解为什么customerId.getCustomer()总是返回null吗

我的XSD(部分):

生成的类CustomerId:
@xmlacessortype(xmlacesstype.FIELD)
@XmlType(name=“customer\u id”,proporter={“customer”})
公共类客户ID{
受保护的身份证客户;
公共Id getCustomer(){
退货客户;
}
公共无效设置客户(Id值){
这就是顾客=价值;
}
}
为Id生成的类看起来很相似,我不认为有什么特别的。 在我的请求处理程序中,我得到了以下摘录:

处理程序:
JAXBElement-request=requestHandler.unmarshallRequest(inputStream);
对象jaxbClass=request.getDeclaredType();
expectedClass=CustomerId.class;
//下一行不会对给定的XML引发异常
如果(jaxbClass!=expectedClass)抛出新的IllegalArgumentException();
CustomerId CustomerId=(CustomerId)request.getValue();
if(customerId==null){
logInfo(“customerId:null”);
}else if(customerId.getCustomer()==null){
//这是将永远被执行的部分…为什么?
logInfo(“customerId.customer:null”);
}否则{
logInfo(“客户id:+customerId.getCustomer().getId());
//返回mbean.getCustomer(customerId);
}
最后是一个示例请求XML:

我去掉了肥皂信封和身体标签,因为这不会引起任何麻烦。 谁能看出我做错了什么?(我很确定,我知道……)
谢谢你的夸奖

第一部分

当我创建一个新Id并设置customerId.customer时,完整的 输出为


第二部分

在请求中将m:prefix放入customer元素时,解析器 投诉他找到了m:客户和预期客户

这意味着您的XML架构与映射不匹配。如果希望
customer
元素位于名称空间中,则可以将XML模式更改为以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns:tip="http://example.org/tip" 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://example.org/tip/pro"
    elementFormDefault="qualified">

    ...

</schema>

...
有关JAXB和名称空间的更多信息,请参阅:


如果封送对象的一个实例,则生成的XML与您输入的XML相比是什么样子的?看起来是这样的:如果封送一个完全填充的对象模型,您就会得到它?嗯,是的。这是我从服务器日志中获取的完整输出。@BlaiseDoughan:您的问题告诉我,我的完全限定对象模型的输出应该有很大的不同。预期的产出是多少?除了缺少的(自空)customer元素之外,我看不到太奇怪的东西。感谢您提供了这个清晰的答案和有用的链接。我会试试这个,然后回来把你的答案标记为一个解决方案,我相信它会解决我的问题。我有一个月的时间为这个客户安排了很多其他优先事项,所以这个问题需要等待。但最后你的回答让我找到了解决办法。
<?xml version="1.0" encoding="ISO-8859-1"?>
<m:get_customer_request xmlns:m="http://example.org/tip/pro">
  <m:customer id="0" name="help"/>
</m:get_customer_request>
<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns:tip="http://example.org/tip" 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://example.org/tip/pro"
    elementFormDefault="qualified">

    ...

</schema>