https://github.com/microbean/microbean-jackson-cdi
CDI integration for Jackson.
https://github.com/microbean/microbean-jackson-cdi
Last synced: 10 months ago
JSON representation
CDI integration for Jackson.
- Host: GitHub
- URL: https://github.com/microbean/microbean-jackson-cdi
- Owner: microbean
- License: apache-2.0
- Created: 2018-05-07T20:03:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-05T22:32:33.000Z (over 6 years ago)
- Last Synced: 2025-04-03T19:33:10.055Z (about 1 year ago)
- Language: Java
- Size: 410 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# microBean™ [Jackson](https://github.com/FasterXML/jackson) CDI Integration
[](https://travis-ci.com/microbean/microbean-jackson-cdi)
[](https://maven-badges.herokuapp.com/maven-central/org.microbean/microbean-jackson-cdi)
The microBean™ Jackson CDI Integration project provides a CDI portable
extension that allows
[`ObjectMapper`](https://fasterxml.github.io/jackson-databind/javadoc/2.10/com/fasterxml/jackson/databind/ObjectMapper.html)
instances to be injected in your CDI-based application.
## Installation
Declare a dependency in your CDI-based Maven project:
```
org.microbean
microbean-jackson-cdi
1.0.0
```
## Usage
Inject an `ObjectMapper` into a CDI bean:
```
import javax.enterprise.inject.Default;
import javax.inject.Inject;
import com.fasterxml.jackson.databind.ObjectMapper;
// This will be the default ObjectMapper.
@Inject
private ObjectMapper objectMapper;
// This will be the same ObjectMapper as above.
@Inject
@Default
private ObjectMapper defaultObjectMapper;
// This will be another ObjectMapper.
@Inject
@YourQualifierHere
private ObjectMapper specialObjectMapper;
```
## Customization
To customize the `ObjectMapper` created by the portable extension
furnished by this project, observe an `ObjectMapper`-typed CDI event:
```
private static final void onDefaultObjectMapperCreation(@Observes final ObjectMapper objectMapperBeingCreated) {
// The ObjectMapper received here is the default one and is in the process of
// being registered in application scope. You may customize it here, but do
// not retain a reference to it. Here is an arbitrary example.
objectMapperBeingCreated.setLocale(java.util.Locale.getDefault());
}
private static final void onQualifiedObjectMapperCreation(@Observes @YourQualifierHere final ObjectMapper yellowObjectManagerBeingCreated) {
// The ObjectMapper received here is the @YourQualifierHere-qualified one from
// the example above and is in the process of being registered in application
// scope. You may customize it here, but do not retain a reference to it.
// Here is an arbitrary example.
yellowObjectMapperBeingCreated.setTimeZone(java.util.TimeZone.getTimeZone("GMT-8"));
}
```