将 java 从 1.8.0_77 更新到 1.8.0_121 后,JAXB 不会解组 [英] JAXB doesn't unmarshall after updating java from 1.8.0_77 to 1.8.0_121

查看:18
本文介绍了将 java 从 1.8.0_77 更新到 1.8.0_121 后,JAXB 不会解组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我更新了标题中发布的java,现在JAXB不再解析xml了.所有对象都只是空,似乎没有设置.

Yesterday I updated java like posted in the title, now JAXB doesn't parse xml anymore. All objects are simply null, nothing seems to be set.

鉴于此 POJO - ListMatchingProductsResponse

Given this POJO - ListMatchingProductsResponse

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ListMatchingProductsResponse", propOrder = {
        "listMatchingProductsResult",
        "responseMetadata"
})
@XmlRootElement(name = "ListMatchingProductsResponse")
public class ListMatchingProductsResponse {
    @XmlElement(name = "ListMatchingProductsResult")
    private ListMatchingProductsResult listMatchingProductsResult;
    @XmlElement(name = "ResponseMetadata")
    private ResponseMetadata responseMetadata;
    @XmlAttribute(name = "xmlns")
    private String xmlns;

    public String getXmlns() {
        return xmlns;
    }

    public void setXmlns(String xmlns) {
        this.xmlns = xmlns;
    }


    /**
     * Get the value of ListMatchingProductsResult.
     *
     * @return The value of ListMatchingProductsResult.
     */
    public ListMatchingProductsResult getListMatchingProductsResult() {
        return listMatchingProductsResult;
    }

    /**
     * Set the value of ListMatchingProductsResult.
     *
     * @param listMatchingProductsResult The new value to set.
     */
    public void setListMatchingProductsResult(ListMatchingProductsResult listMatchingProductsResult) {
        this.listMatchingProductsResult = listMatchingProductsResult;
    }

    /**
     * Get the value of ResponseMetadata.
     *
     * @return The value of ResponseMetadata.
     */
    public ResponseMetadata getResponseMetadata() {
        return responseMetadata;
    }

    /**
     * Set the value of ResponseMetadata.
     *
     * @param responseMetadata The new value to set.
     */
    public void setResponseMetadata(ResponseMetadata responseMetadata) {
        this.responseMetadata = responseMetadata;
    }
}

还有 ListMatchingProductsResult

And the ListMatchingProductsResult

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="ListMatchingProductsResult", propOrder={
    "products"
})
@XmlRootElement(name = "ListMatchingProductsResult")
public class ListMatchingProductsResult {

    @XmlElement(name="Products")
    private ProductList products;

    /**
     * Get the value of Products.
     *
     * @return The value of Products.
     */
    public ProductList getProducts() {
        return products;
    }

    /**
     * Set the value of Products.
     *
     * @param products
     *            The new value to set.
     */
    public void setProducts(ProductList products) {
        this.products = products;
    }

    /**
     * Check to see if Products is set.
     *
     * @return true if Products is set.
     */
    public boolean isSetProducts() {
        return products != null;
    }


    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("products", products)
                .toString();
    }
}

我用它来解组:

String s = getResult();
// s is the expected xml string
ListMatchingProductsResponse m = JAXB.unmarshal(new StringReader(s), ListMatchingProductsResponse.class);
log.info(m); // ListMatchingProductsResponse@7164e54
log.info(m.getListMatchingProductsResult()); // null

我有点不知所措,因为我没有看到任何原因,也没有在更新日志中找到有关 JAXB 的任何更改.

I'm a bit lost as I don't see any kind of reason for this, nor did I find any changes regarding JAXB in the changelog.

我在这里做错了什么?

到目前为止,以下答案并没有解决我的问题

The following answers didn't solve my issue so far

JAXB 配置因集合从 JDK 1.7 升级到 JDK 1.8 u05 而被破坏

解组 jaxB 不起作用,对象为空

使用 JAXB 解组不起作用

更新

我现在已将以下依赖项包含到我的项目中

I now have included the following dependency to my project

group: 'org.jvnet.jaxb2.maven2', name: 'maven-jaxb2-plugin', version: '0.13.1'

它再次工作.这么新的问题——为什么会这样?121 java 版本中是否缺少某些内容/错误?

and it works again. So new question - why is that? Is there something missing / a bug in the 121 java release?

推荐答案

我已经编辑了这个,事实证明,JRE 中的更改在技术上并不是一个错误,但是 1.8u91 和以前的版本更宽松,允许命名空间 XML 无效,如果 xml 命名空间不正确,则 1.8u101+ 会中断.

I have edited this, as it turns out that the change in the JRE was not technically a bug, but 1.8u91 and previous versions were more lenient, and allowed invalid namespaced XML, and 1.8u101+ breaks if xml is not correctly namespaced.

我在 GitHub 上创建了一个示例来说明差异.尝试使用 1.8u91 和 1.8u101+ 运行两个主要的 NoSchemaWithSchema 以查看行为差异.

I have created an example on GitHub to illustrate the difference. Try two run the two mains NoSchema and WithSchema using 1.8u91, and 1.8u101+ to see the difference in behaviour.

在我的例子中,XML 不包含默认命名空间,但元素没有以它们所属的命名空间(broker.xml)作为前缀.这在 1.8u91 中运行良好,但在 1.8u101 中失败.虽然升级破坏了我们的代码,但这在技术上并不是 Oracle 的错误,因为 XML 的命名空间不正确.

In my case the XML contained no default namespace, but the elements were not prefixed with the namespace they belonged to (broker.xml). This worked fine in 1.8u91, but failed in 1.8u101. Although upgrading broke our code, this is technically not Oracles fault, since the XML was incorrectly namespaced.

这篇关于将 java 从 1.8.0_77 更新到 1.8.0_121 后,JAXB 不会解组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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