jsonb-api icon indicating copy to clipboard operation
jsonb-api copied to clipboard

Support AnnotatedType

Open jsonbrobot opened this issue 7 years ago • 4 comments

Since Java 8 introduced TYPE_USE annotations, and this API is a Java standard as well, one would expect the two to work together.

I suggest JSON-B is enhanced (the implementation at least, if not the spec) to support AnnotatedType.

Namely, the following methods should exist:

  • Jsonb#fromJson(String, AnnotatedType)
  • JsonbDeserializer#deserialize(JsonParser, DeserializationContext, AnnotatedType)

The rationale is that the deserializer gains the ability to make decisions based on the type annotations.

E.g. For a type such as List<@Base64 Key> it would be possible to create a (de)serializer that performs custom logic (e.g. Base64-encode/decode the value on the way in/out) for types annotated with @Base64 regardless of their class.

jsonbrobot avatar Jan 01 '18 02:01 jsonbrobot

  • Issue Imported From: https://github.com/javaee/jsonb-spec/issues/66
  • Original Issue Raised By:@kaqqao
  • Original Issue Assigned To: Unassigned

jsonbrobot avatar May 23 '18 22:05 jsonbrobot

@m0mus Commented Added to the next spec version proposed features.

jsonbrobot avatar Feb 23 '18 17:02 jsonbrobot

This would also be useful for conditional formatting such as a view on the JSON (a-la Jackson JSON Views). Not sure if this also means there should be a #deserialze(JsonParser, DeserialisationContext, Annotation... annotations) method too or decomposing to AnnotatedElement as AnnotatedType doesn't cover a parameter or variable use case.

dansiviter avatar Jan 08 '19 11:01 dansiviter

Hi, I'm not sure the goal since Type covers all potential cases of JSON-B as of today and there is no use case we can't cover with such API so can be neat to keep the API sane to avoid indirections and needed overrides in integrations to support way more base API (otherwise customizations will become a mess and no more usable properly since methods will conflicts or builders will be ultra verbose for ex).

rmannibucau avatar May 04 '21 07:05 rmannibucau