jboss 使用JsonTypeInfo.DEDUCTION进行反序列化时出现异常

4xy9mtcn  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(251)

我有 SpringBoot应用程序(1.4.3.RELEASE)。最近我已经将Jackson(com.fasterxml.jackson.datatype, com.fasterxml.jackson.core)从2.8.5升级到2.12.2,因为有多态子类型演绎功能。在单元测试期间,以及从IDE运行应用程序时,在我的本地开发环境中一切都运行良好。
当我推送我的更改以在开发环境中构建和部署它时,出现了这个问题,其中应用程序部署在 Wildfly 21.0.2 上(作为WAR存档)。调用ObjectMapper#readValue会引发java.lang.EnumConstantNotPresentException(下面详细介绍了堆栈)。
我正在反序列化的对象中没有使用枚举,我已经通过Wildfly管理控制台检查了,在部署的应用程序上有正确的Jackson版本。现在我有点不知所措。有什么想法吗?

com.fasterxml.jackson.annotation.JsonTypeInfo$Id.DEDUCTION
at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector._findTypeResolver(JacksonAnnotationIntrospector.java:1424)
at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.findTypeResolver(JacksonAnnotationIntrospector.java:522)
at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findTypeResolver(AnnotationIntrospectorPair.java:225)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1584)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findPropertyTypeDeserializer(BasicDeserializerFactory.java:1748)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.resolveMemberAndTypeAnnotations(BasicDeserializerFactory.java:2116)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.constructCreatorProperty(BasicDeserializerFactory.java:1000)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._addExplicitPropertyCreator(BasicDeserializerFactory.java:634)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._addDeserializerConstructors(BasicDeserializerFactory.java:407)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:283)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:224)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:220)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:414)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:479)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4405)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4214)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
jogvjijk

jogvjijk1#

好吧,通过在jboss-deployment-structure.xml文件中显式排除Jackson相关库,解决了该问题(如下面的代码所示)。如果没有这些排除,Wildfly将强制其自己的Jackson库,该库位于/wildfly/modules/system/layers/base/ path (e.g. wildfly/modules/system/layers/base/com/fasterxml/jackson/core/jackson-core)中,对于Wildfly 21.0.2为2.10.5。Wildfy将这样做,而不考虑在maven pom.xml中指定自定义版本。此外,我没有"我无法通过管理控制台在Wildfly中找到任何关于这个"嵌入式" Jackson版本的内容,所以要意识到问题出在哪里有点痛苦。也许这会为其他人节省一些时间。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
    <deployment>
        <exclusions>
            <module name="com.fasterxml.jackson.core.jackson-core" />
            <module name="com.fasterxml.jackson.core.jackson-databind" />
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" />
            <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
        </exclusions>
        <dependencies>
            <module name="jdk.unsupported"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

相关问题