Skip to content

Commit

Permalink
Polish ContextResolver beans
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 8, 2023
1 parent edb23c9 commit 9d08524
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.Provider;
Expand All @@ -14,8 +13,11 @@
@Priority(Priorities.USER + 10) // give it a priority that ensures that user supplied ContextResolver classes override this one
public class QuarkusObjectMapperContextResolver implements ContextResolver<ObjectMapper> {

@Inject
ObjectMapper objectMapper;
private final ObjectMapper objectMapper;

public QuarkusObjectMapperContextResolver(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

@Override
public ObjectMapper getContext(Class<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.json.bind.Jsonb;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.ext.ContextResolver;
Expand All @@ -13,8 +12,11 @@
@Priority(Priorities.USER + 10) // give it a priority that ensures that user supplied ContextResolver classes override this one
public class QuarkusJsonbContextResolver implements ContextResolver<Jsonb> {

@Inject
Jsonb jsonb;
private final Jsonb jsonb;

public QuarkusJsonbContextResolver(Jsonb jsonb) {
this.jsonb = jsonb;
}

@Override
public Jsonb getContext(Class<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.concurrent.ConcurrentHashMap;

import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.xml.bind.JAXBContext;

Expand All @@ -12,13 +11,17 @@

public class JAXBContextContextResolver implements ContextResolver<JAXBContext> {

private ConcurrentHashMap<Class<?>, JAXBContext> cache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Class<?>, JAXBContext> cache = new ConcurrentHashMap<>();

@Inject
Instance<JaxbContextCustomizer> customizers;
private final Instance<JaxbContextCustomizer> customizers;

@Inject
JaxbContextProducer jaxbContextProducer;
private final JaxbContextProducer jaxbContextProducer;

public JAXBContextContextResolver(Instance<JaxbContextCustomizer> customizers,
JaxbContextProducer jaxbContextProducer) {
this.customizers = customizers;
this.jaxbContextProducer = jaxbContextProducer;
}

@Override
public JAXBContext getContext(Class<?> clazz) {
Expand Down

0 comments on commit 9d08524

Please sign in to comment.