jakartaee / jakartaee/jsonb-api
Automatically Apply jsonbadapaters
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
In the spirits of what JPA has done with ```AttributeConverter(autoApply=true)```
* I would suggest the following changes and implementation of the JsonbtypeAdapter:
```java
@JsonbAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD,ElementType.TYPE})
public @interface JsonbTypeAdapter {
//Defines if the runtime should automatically use the following adapter
//for all types as defined by the adapter implementation generic-type
//default is false
boolean autoApply() default false;
}
```
* The adapter interface adaptation
```java
//Where generic-type V determines the actual type for which this adapter is associated.
public interface JsonbAdapter {
//Adapts the user property specified to a marshallable json capable type
B adaptTo(V value);
V adaptFrom(B value)
}
```
* Then an example usages:
```java
//In this case, the jsonb runtime should apply this adapter to all properties and types, for which the type is Normaltype.
//These adapters could technically be registered on application startup (for javaee)
@JsonTypeAdapter(autoApply=true)
public class CustomTypeAdapater implements JsonbAdapter {
}
// example
public class CustomObject {
//Automatically, the json runtime will apply the CustomTypeAdapater without user explicitly specifying the values.
private NormalType2 normaltype;
}
```
* and, from which the user has to specifically annotate the field with
```java
@JsonTypeAdapter(autoApply=false)
public class CustomTypeAdapater2 implements JsonbAdapter {
}
// and interface
public interface JsnobAdapted {
Class adapter();
}
//Example usage
public class CustomObject2 {
@JsnobAdapted(CustomTypeAdapater2.class)
private NormalType2 normaltype;
}
```
Contributor guide
Research direction
Start by reviewing the existing JsonbTypeAdapter and JsonbAdapter API definitions, then trace how adapters are registered and selected. A complete change would specify and implement autoApply handling, generic-type matching, startup registration, and explicit field-level adapter selection, with tests for both automatic and opt-in 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
- Needs clarification
- Newbie friendliness
- 20/100