jakartaee / jakartaee/jsonb-api
Introspection API
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
Jackson has some handy JSON introspection APIs that could be useful for things like generating GraphQL schemas or OpenAPI templates, etc. It would be nice if JSON-B offered similar APIs to allow a user to query JSON fields based on the annotations on a given entity class.
As an example, suppose you want to generate a GraphQL schema from the following entity class:
```java
public class Widget {
private String name;
@JsonbProperty("qty")
private int quantity = -1;
private double weight = -1.0;
@JsonbTransient
private Object ignorableObject;
...
@JsonbProperty("tonnage")
private int setWeight(double weight) {
this.weight = weight;
}
...
}
```
I would expect to be able to take the `Widget` class, introspect it and generate a GraphQL schema snippet like this:
```
input WidgetInput @_mappedType(type : "__internal__") {
name: String @_mappedInputField(inputField : "__internal__")
qty: Int! @_mappedInputField(inputField : "__internal__")
tonnage: Float! @_mappedInputField(inputField : "__internal__")
}
```
Note that `@JsonbProperty` and `@JsonbTransient` annotations are taken into account.
Ideally, an API might exist similar to this:
```
JsonbSchema schema = Jsonb.schemaFromClass(Widget.class);
Map serializedFieldNames = schema.getSerializedFieldNamesAndTypes();
// for each entry in the map, write out the GraphQL schema using the field name and converting the JSON ValueType to GraphQL type
```
Likewise it would be good to also get the `deserializedFieldNames` so that users could accurately predict what JSON fields will exist when deserializing an instance of the specified class.
The actual API isn't as important to me as is the ability to easily get the JSON schema that would be used when serializing/deserializing an instance of a given class.
Thanks for considering!
Contributor guide
Research direction
Start with the proposed Jsonb.schemaFromClass(Widget.class) entry point and the serializedFieldNamesAndTypes and deserializedFieldNames operations described in the issue. Check how the example's JsonbProperty and JsonbTransient annotations should affect the results. Done means a considered JSON-B introspection API can expose the relevant serialized and deserialized field names and value types.
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
- 30/100