Jackson完全忽略了Jaxb XML相关的注释

问题描述

想象一下,当您使用Java建立模型时,必须将其序列化为XML和CSV。

我将Jaxb Marshaller用于XML,将Jackson的CsvMapperObjectMapper)用于CSV。

由于格式略有不同,我希望Jackson的CsvMapper忽略与Jaxb@XmlType之类的@XmlElement相关的注释。因为Jackson也在获取信息/考虑xml注释,这会导致错误的结果。

我该怎么办?

解决方法

这是您可能创建新的window.addEventListener("orientationchange",function (event) { const { angle } = event.target.screen.orientation; // orientation angle let orientation = angle === 90 || angle === -90 ? "landscape" : "portrait"; const element = document.getElementById("#customElement"); element.classList.remove(['landscape',"portrait"]); element.classList.add(orientation); }); 的方式:

CsvMapper

CsvMapper csvMapper = new CsvMapper(); csvMapper.findAndRegisterModules(); 方法将调用findAndRegisterModules,该文档指出:

使用JDK ServiceLoader工具以及模块提供的SPI定位可用方法的方法。

因此,可能您在类路径上有jackson-module-jaxb-annotations模块,这就是findModules识别CsvMapper注释的原因。

要修复此问题,您需要删除对此方法JAXB的调用,并仅注册所需的这些模块。