@Override
@SuppressWarnings("deprecation")
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.rawClass(typeHint);
if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) {
JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class);
schemaType = schemaInfo.schemaType();
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) {
objectProperties = schemaInfo.schemaObjectPropertiesDefinition();
}
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) {
itemDefinition = schemaInfo.schemaItemDefinition();
}
}
}
/* 19-Mar-2012, tatu: geez, this is butt-ugly abonimation of code...
* really, really should not require back ref to an ObjectMapper.
*/
objectNode.put("type", schemaType);
if (objectProperties != null) {
try {
objectNode.put("properties", _getObjectMapper().readTree(objectProperties));
} catch (IOException e) {
throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value");
}
}
if (itemDefinition != null) {
try {
objectNode.put("items", _getObjectMapper().readTree(itemDefinition));
} catch (IOException e) {
throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaItemDefinition value");
}
}
// always optional, no need to specify: