我正在从EAP6.4/JDK8 -> EAP7.2/JDK11
升级应用程序,而我的XML解析似乎无法正常工作。在升级之前,我能够将以下XML解析为带注释的对象。
如果我从XML中删除前面的app:
,它将进行转换,否则所有内容均为null
。 JDK8和JDK11之间在XML的处理方式方面是否有变化?
输出
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.bind
,以解决jdk11中缺少jaxb的问题。
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
<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>