将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

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

问题描述

昨天我在标题中更新了java like,现在JAXB不再解析xml了。所有对象都是null,似乎没有设置任何东西。

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

通过从JDK 1.7升级到JDK 1.8 u05收集来破坏JAXB配置

< a href =https://stackoverflow.com/questions/28771769/unmarshalling-jaxb-doesnt-work-objects-null>解组jaxB无效,对象无效

Unmarshall with 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中技术上并不是一个bug,但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 上创建了一个示例,以说明其差异。尝试两个运行两个主电源 NoSchema WithSchema 使用1.8u91和1.8u101 +来查看行为差异。

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中失败了。虽然升级破坏了我们的代码,但这在技术上并不是Oracles的错误,因为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天全站免登陆