簡體   English   中英

XML JDK11/EAP7升級后解析中斷

[英]XML Parsing Broken after JDK11/EAP7 upgrade

我正在從EAP6.4/JDK8 -> EAP7.2/JDK11升級應用程序,我的 XML 解析似乎不一樣。 在升級之前,我能夠將以下 XML 解析為帶注釋的 object。

沒有編譯或運行時錯誤,應用程序部署。

如果我刪除前面的app:從 XML 它將轉換,否則一切都是null 有沒有辦法在忽略命名空間app:的同時解組這個 xml:?

Output

XML{id='null', time=null, type='null', description='null', time=null}

XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<app:exampleXML xmlns:app="http://www.example.com/schemas/schema">
<app:id>app-id</app:id>
<app:time>2020-06-05T13:17:00.899Z</app:time>
<app:type>test</app:type>
<app:description>Test</app:description>
</app:exampleXML>

Object

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.time.Instant;
import java.util.UUID;

@XmlRootElement(name = "exampleXML", namespace="http://www.example.com/schemas/schema")
@XmlAccessorType(XmlAccessType.FIELD)
public class XML {
    public static final int DESCRIPTION_LENGTH = 4000;

    @XmlElement(name = "id", required = true)
    private String id;


    @XmlElement(name = "time", required = true)
    @XmlJavaTypeAdapter(InstantXmlAdapter.class)
    @JsonSerialize(using = InstantJsonSerializer.class)
    @JsonDeserialize(using = InstantJsonDeserializer.class)
    private Instant time;

    @XmlElement(name = "type", required = true)
    private CheckpointLevel type;

    @XmlElement(name = "description")
    @XmlJavaTypeAdapter(CDATAXmlAdapter.class)
    private String description;

編輯:

我在我的 gradle 構建中實現了jakarta ,以解決 jdk11 中缺少 jaxb 的問題。

implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"

從版本 9 開始,JAXB 已從 JDK 中刪除。 您需要將它們添加為單獨的依賴項。 如果您使用 Maven 或 Gradle 您可以使用 Maven 存儲庫:

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-core</artifactId>
  <version>2.3.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.3.0</version>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM