英文:
XML Parsing Broken after JDK11/EAP7 upgrade
问题
以下是翻译好的部分:
输出
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>
对象
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
,以弥补 JDK 11 中缺少 jaxb 的问题。
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
请注意,以上内容已经完成翻译,如果还有其他需要翻译的内容,请提供。
英文:
I'm upgrading an app from EAP6.4/JDK8 -> EAP7.2/JDK11
and my XML parsing doesn't seem to be working the same. Before the upgrade I was able to parse the following XML into an annotated object.
No compile or runtime errors, app deploys.
If I remove the preceding app:
from the XML it'll convert, else everything is null
. Is there a way to unmarshall this xml while ignoring the namespace app:
?
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;
EDIT:
I'm implementing jakarta
in my gradle build to account for the lack of jaxb in jdk11.
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
答案1
得分: 1
从版本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>
英文:
Starting from version 9 JAXB was removed from JDK. You need to add them as separate dependencies. If you are using Maven or Gradle you can use Maven repository for that:
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论