Skip to content

Commit

Permalink
Merge pull request #45408 from geoand/rr-jackson-beans
Browse files Browse the repository at this point in the history
Make Quarkus REST Jackson beans ApplicationScoped
  • Loading branch information
geoand authored Jan 10, 2025
2 parents dc41fd1 + 1e63ad9 commit 8da6801
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SynthesisFinishedBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.processor.DotNames;
import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
Expand Down Expand Up @@ -163,7 +164,9 @@ AdditionalBeanBuildItem beans() {
// just because it's a bean.
// Whether it is used in RESTEasy Reactive is determined elsewhere
.addBeanClass(FullyFeaturedServerJacksonMessageBodyWriter.class)
.setUnremovable().build();
.setDefaultScope(DotNames.APPLICATION_SCOPED)
.setUnremovable()
.build();
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public abstract class AbstractServerJacksonMessageBodyReader extends AbstractJso

protected final LazyValue<ObjectReader> defaultReader;

// used by Arc
protected AbstractServerJacksonMessageBodyReader() {
defaultReader = null;
}

public AbstractServerJacksonMessageBodyReader(Instance<ObjectMapper> mapper) {
this.defaultReader = new LazyValue<>(new Supplier<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class BasicServerJacksonMessageBodyWriter extends ServerMessageBodyWriter
private final LazyValue<ObjectWriter> defaultWriter;
private final Map<JavaType, ObjectWriter> genericWriters = new ConcurrentHashMap<>();

// used by Arc
public BasicServerJacksonMessageBodyWriter() {
defaultWriter = null;
}

@Inject
public BasicServerJacksonMessageBodyWriter(Instance<ObjectMapper> mapper) {
this.defaultWriter = new LazyValue<>(new Supplier<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class FullyFeaturedServerJacksonMessageBodyReader extends AbstractServerJ
private final ConcurrentMap<Class<?>, ObjectMapper> contextResolverMap = new ConcurrentHashMap<>();
private final ConcurrentMap<ObjectMapper, ObjectReader> objectReaderMap = new ConcurrentHashMap<>();

// used by Arc
public FullyFeaturedServerJacksonMessageBodyReader() {
originalMapper = null;
providers = null;
}

@Inject
public FullyFeaturedServerJacksonMessageBodyReader(Instance<ObjectMapper> mapper, Providers providers) {
super(mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public class FullyFeaturedServerJacksonMessageBodyWriter extends ServerMessageBo
private final ConcurrentMap<Class<?>, ObjectMapper> contextResolverMap = new ConcurrentHashMap<>();
private final ConcurrentMap<ObjectMapper, ObjectWriter> objectWriterMap = new ConcurrentHashMap<>();

// used by Arc
public FullyFeaturedServerJacksonMessageBodyWriter() {
originalMapper = null;
providers = null;
defaultWriter = null;
}

@Inject
public FullyFeaturedServerJacksonMessageBodyWriter(Instance<ObjectMapper> mapper, Providers providers) {
this.originalMapper = mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
public class ServerJacksonMessageBodyReader extends AbstractServerJacksonMessageBodyReader
implements ServerMessageBodyReader<Object> {

// used by Arc
public ServerJacksonMessageBodyReader() {

}

@Inject
public ServerJacksonMessageBodyReader(Instance<ObjectMapper> mapper) {
super(mapper);
Expand Down

0 comments on commit 8da6801

Please sign in to comment.