Open jansupol opened 9 years ago
@glassfishrobot Commented Reported by marembo2008
@glassfishrobot Commented rmannibucau said: Jsonb relies on a config instance which can hold this. JPA supports it cause it supports scanning of (explicit or not) managed types. For me this JPA spirit doesnt match jsonb even if the "global" need needs to be there.
@glassfishrobot Commented This issue was imported from java.net JIRA JSONB_SPEC-35
In the spirits of what JPA has done with
AttributeConverter(autoApply=true)
The adapter interface adaptation``` //Where generic-type V determines the actual type for which this adapter is associated. public interface JsonbAdapter<V, B> {
//Adapts the user property specified to a marshallable json capable type B adaptTo(V value);
V adaptFrom(B value) }
Then an example usages:``` //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<NormalType, Customtype> { }
/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``` @JsonTypeAdapter(autoApply=false) public class CustomTypeAdapater2 implements JsonbAdapter<NormalType2, Customtype2> { }
// and interface public interface JsnobAdapted {
Class<? extends JsonbAdapter> adapter(); }
//Example usage public class CustomObject2 {
@JsnobAdapted(CustomTypeAdapater2.class) private NormalType2 normaltype; }