@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode objectNode = createObjectNode();
String schemaType = "any";
String objectProperties = null;
String itemDefinition = null;
if (typeHint != null) {
Class<?> rawClass = TypeFactory.type(typeHint).getRawClass();
if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) {
JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class);
schemaType = schemaInfo.schemaType();
if (!"##irrelevant".equals(schemaInfo.schemaObjectPropertiesDefinition())) {
objectProperties = schemaInfo.schemaObjectPropertiesDefinition();
}
if (!"##irrelevant".equals(schemaInfo.schemaItemDefinition())) {
itemDefinition = schemaInfo.schemaItemDefinition();
}
}
}
objectNode.put("type", schemaType);
if (objectProperties != null) {
try {
objectNode.put("properties", new ObjectMapper().readValue(objectProperties, JsonNode.class));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
if (itemDefinition != null) {
try {
objectNode.put("items", new ObjectMapper().readValue(itemDefinition, JsonNode.class));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
// always optional, no need to specify: