0

I try to inject an ObjectMapper using fasterXML jackson like this:

@Inject
private ObjectMapper objectMapper;

but i have the next error when i try to deploy the war file:

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ObjectMapper with qualifiers @Default

This are my dependencies:

    <!-- 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>

What i did wrong?

Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44

1 Answers1

0

I am making the assumption you need the ObjectMapper to do some configuration on it. For this you can use:

@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;
    }

}
Albert Bos
  • 2,012
  • 1
  • 15
  • 26