How to remove the id field ("id" : "urn:jsonschema:org:gradle:Person") from JSON schema created using Jackson?
Generated Schema
{
"type" : "object",
"id" : "urn:jsonschema:org:gradle:Person",
"properties" : {
"name" : {
"type" : "string"
}
}
}
For POJO class (Person.class)
import com.fasterxml.jackson.annotation.JsonProperty;
public class Person {
@JsonProperty("name")
private String name;
}
Using JSON Schema Generator
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
public final class GetJsonSchema {
public static String getJsonSchema2(Class clazz) throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(mapper);
JsonSchema jsonSchema = jsonSchemaGenerator.generateSchema(clazz);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
}
}
Invoked like
System.out.println(JsonSchema.Create(Person.class));