Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0.SP1</version>
</dependency>
</dependencies>

<build>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/devcon5/jsonb/jackson/JacksonJsonbBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/

package io.devcon5.jsonb.jackson;
import java.util.Optional;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
Expand All @@ -27,6 +31,7 @@
/**
* Jackson2 based implmentation of Jsonb API
*/
@ApplicationScoped
public class JacksonJsonbBuilder implements JsonbBuilder {

/**
Expand Down Expand Up @@ -60,11 +65,13 @@ public JsonbBuilder withProvider(final JsonProvider jsonProvider) {
//noop
return this;
}


@Inject
private Provider<ObjectMapper> mapper;

@Override
public Jsonb build() {

final ObjectMapper mapper = new ObjectMapper();
final ObjectMapper mapper=Optional.ofNullable(this.mapper).map(Provider::get).orElseGet(ObjectMapper::new);
if(!includeNulls){
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
if(!includeEmpty){
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
</beans>