-
Notifications
You must be signed in to change notification settings - Fork 41
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:
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<String,ValueType> 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!