jakartaee / jakartaee/jsonb-api
Jsonb as a CDI bean must support CDI Jsonb component lookup must not standalone instances
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
Today if you do:
> jsonb = JsonbBuilder.create()
and map a model using a cdi adapter bound with
> @JsonbTypeAdapter(MyCDIImpl.class)
then it works whereas it must not.
However if you would do:
> @Inject Jsonb jsonb;
it should work
The issue not respecting that is you never know when creating a jsonb instance if CDI must be used or not. When aggregating libraries and inheriting from jsonb "standalone" instances you can end up using a CDI bean and make the SE library misbehave.
The other issue for implementation is to know CDI must be used or not, in some environment like OSGi it is almost impossible - leading to dropping that feature.
Therefore the proposal of this ticket is to:
1. Make it correctly define - stadanlone instance are not CDI friendly, add a Jsonb CDI bean, and make only this jsonb instance cdi friendly
2. Add a jsonb.enableCDI boolean property (no need to define a constant or setter, config.setProperty is fine) to enable to switch back to v1.
Note: doing 2 in the other way is a workaround but keeps existing code broken. I understand changing 1.+2. can break code also but since it is saner and both options break some libs/apps I think it is worth make it clean now (+ it is very rarely used).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JsonbBuilder.create() and @Inject Jsonb entry points described in the issue, and trace how @JsonbTypeAdapter(MyCDIImpl.class) is resolved. Define completion as standalone instances not using CDI, the injected CDI bean remaining CDI-friendly, and the jsonb.enableCDI property restoring the previous behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100