Using org.codehaus.jackson.map.ObjectMapper
(NOT the databind version!) I'm generating a json schema from the following object:
public class MyModelObject {
private long fileSize;
//... other properties, getters, setters etc
}
Using the following code:
ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.generateJsonSchema(clazz);
String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
I get the following schema (stripped down to the relevant part):
{
"type" : "object",
"properties" : {
"fileSize" : {
"type" : "number"
}
}
}
"number" is not the best representation of a long, as when I elsewhere try to generate pojos FROM the schema, I get "double" rather than "long" (or even "int" would be ok).
According to this, there is an "integer" data type in json that would suit my needs much better: http://spacetelescope.github.io/understanding-json-schema/reference/numeric.html
But digging through the source code of the jackson-mapper module, I found that they're using a standard serializer called LongSerializer
contained in this class: org.codehaus.jackson.map.ser.StdSerializers
The relevant part is this method:
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
return createSchemaNode("number", true);
}
Long story short: Is it possible to override the standard serializers, or do I need to go in and hack my generated output?