WELD-001408:对于带有限定符@Default at的ObjectMapper类型的不满意依赖项

时间:2017-04-03 15:00:16

标签: java-ee-7 wildfly-10 fasterxml jackson2 jackson-databind

我尝试使用fastXML jackson注入一个ObjectMapper,如下所示:

@Inject
private ObjectMapper objectMapper;

但是当我尝试部署war文件时,我有下一个错误:

  

org.jboss.weld.exceptions.DeploymentException:WELD-001408:   带有限定符的 ObjectMapper 类型的不满意依赖项   的 @default

这是我的依赖:

    <!-- the core, which includes Streaming API, shared low-level abstractions (but NOT data-binding) -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson-2-version}</version>
    </dependency>
    <!-- Just the annotations; use this dependency if you want to attach annotations
         to classes without connecting them to the code. -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>${jackson-2-version}</version>
    </dependency>
    <!-- databinding; ObjectMapper, JsonNode and related classes are here -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson-2-version}</version>
    </dependency>
    <!-- jackson-dataformat-yaml: Support for reading and writing YAML-encoded data via Jackson abstractions -->
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <version>${jackson-2-version}</version>
    </dependency>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我假设您需要ObjectMapper对其进行一些配置。为此,您可以使用:

@Provider
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {

    private final ObjectMapper mapper;

    public ObjectMapperContextResolver() {
        mapper = new ObjectMapper();
        // Do some configuration here
    }

    @Override
    public ObjectMapper getContext(Class<?> type) {
        return mapper;
    }

}