1

I intend to convert my POJOs to a JSON Schema.

In the existing POJOs we have annotations from the codehaus package: @JsonProperty("address") where the corresponding import is:

import org.codehaus.jackson.annotate.JsonProperty;

I can't use codehaus api to generate the schema as we have a recursive JSON structure and I get StackOverflowError.

So, I tried using the fasterxml's jackson-module-jsonschema API to do this which works fine.

Sample output that I'm getting:

"Registration" : {
      "type" : "object",
      "id" : "urn:jsonschema:com:xyz.abc.Address",
}

I have two requirements:

  • Apart from "type" and "id", I also want to have a description attribute. I can add @JsonPropertyDescription attribute, which would work, but then each property will have one annotation from codehaus and another one from the fasterxml package. Is there an equivalent annotation in codehaus which can be used for this purpose?

  • Is there a way to have just the un-qualified class name in the "id" attribute (only "Address" i.e. without the qualified object path "xyz.abc.Address" and without "urn:jsonschema") ?

Code for schema generation using fasterxml:

ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(DashboardDef.class);
String generatedJsonSchema = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
Sumeet
  • 11
  • 1

1 Answers1

0

If it is possible just replace codehaus annotation by fasterxml one. codehaus is not supported anymore and should be avoided. For more info take a look at: org.codehaus.jackson versus com.fasterxml.jackson.core.

If you really want to dive into project with these two libraries you should take a look at AnnotationIntrospector class which allow extra configuration and linking many different libraries with Jackson framework. See similar question: How to make fasterxml ObjectMapper work with codehaus annotations.

To manipulate JSON Schema you can implement your own SchemaFactoryWrapper. See also:

PS: I know this is not ideal answer (it does not contain direct solution) but I wanted point you some topics which you should start from to solve your problems, and comments are too small for this.

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146