Open hantsy opened 1 month ago
This cannot work as you show. Once the ContextResolver<Jsonb>
is at hand, the Jsonb
context is obtained based on the supplied (entity) type.
The Spec mandates the following works in every implementation:
@Context Providers providers;
ContextResolver<Jsonb> contextResolver = providers.getContextResolver(Jsonb.class, MediaType.APPLICATION_JSON_TYPE);
Jsonb jsonb = contextResolver.getContext(type);
See Section 10 for mandatory injectable types.
More specifically, the spec requested the JSON-B Message Body provider to automatically utilize the user-provided ContextResolver<Jsonb>
by the JSON-B implementation used by that provider. Using this unified way to obtain the ContextResolver<Jsonb>
. The customer needs just to register the ContextResolver without the need of taking care of the propagation of the Jsonb to the JSON-B implementation.
The customer needs just to register the ContextResolver without the need of taking care of the propagation of the Jsonb to the JSON-B implementation.
Here I want to use jsonb
bean to do some manual serialization work.
When REST embraces CDI, I hope there is a united way to register beans via ContextResolver and CDI context.
@Produces
to create the ConextResolver<Jsonb>
, make jsonb
available in Rest context and CDI context.BTW, more easily for developers, as some frameworks provide, I would like to register a bean to customize JsonbConfig
, then the REST CDI integration module will register ContextResolver<Jsonb>
and produce Jsonb
.
I think the plan was to remove ContextResolver from Jakarta REST with CDI. But I am not sure what the replacement was. That is yet to be discussed.
The example project: https://github.com/hantsy/jakartaee11-sandbox/tree/master/rest
I have created a
@Provider
described like this:As discussed in here, https://github.com/jakartaee/rest/issues/742, a
Jsonb
instance should be available in the context.I tried to inject
Jsonb
, failed.