java - JDK11/EAP7 升级后 XML 解析中断
问题描述
我正在升级一个应用程序EAP6.4/JDK8 -> EAP7.2/JDK11
,我的 XML 解析似乎不一样。在升级之前,我能够将以下 XML 解析为带注释的对象。
没有编译或运行时错误,应用程序部署。
如果我从 XML 中删除前面app:
的内容,它将转换,否则一切都是null
. 有没有办法在忽略命名空间的同时解组这个 xml app:
?
输出
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;
编辑:
我正在jakarta
我的 gradle 构建中实现以解决 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>
推荐阅读
- django - Django 在连接对象中找不到游标对象
- regex - 我怎样才能从 {"d":379} 中检索 379
- asp.net-mvc - 如何从 Owin 中间件正确登录用户
- php - 将 AJAX 实时搜索与 CodeIgniter 结合使用
- python - Python:为什么堆给出不正确的第一次弹出?
- flatbuffers - FlatBuffer:如何构造带有可选子结构/子表的表
- javascript - 将指向数组元素的指针传递给函数
- r - 如何使用 dput() 创建将整个 iris 数据集创建为 JSON 所需的代码
- visual-studio-code - 1.31 更新后禁用文件资源管理器中的键盘导航
- python - 在 Django 中自定义表单验证错误显示