Jackson: json schema references other schemas, can this be disabled?

277 views
Skip to first unread message

Vlad Shelest

unread,
Oct 3, 2014, 4:09:39 PM10/3/14
to jackso...@googlegroups.com

When I use Jackson Json-Schema-Module, my schemas are generated using references that are pointed to each other.

Consider this schema:

This is a property object inside POJO1

    "myObject" : {
     "type" : "object",
     "id": "urn:jsonschema:package:myObject"
     "properties": {
          "property1" : {
             "type" : "string"
         }
          "property2" : {
             "type" : "string"
         }
    }
 }

I have the same property object inside POJO2, and when both schemas get generated, I get the following in POJO2:

  "myObject" : {
     "type" : "object",
     "$ref": "urn:jsonschema:package:myObject"
  }

But I want this property in POJO2'a schema be the same as in POJO1's schema, I don't want the reference. Can this be disabled? Or is there a workaround?

Here's the code I use:

for (Class clazz : classes) {

    ObjectMapper m = new ObjectMapper();
    SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
    m.acceptJsonFormatVisitor(m.constructType(clazz), visitor);
    JsonSchema jsonSchema = visitor.finalSchema();
    m.write(new File("json/" + clazz.getSimpleName() + ".json"), jsonSchema);

}

At first I thought that if use different ObjectMapper instances for each schema construction I would get what I want, but not the case, apparently there's some sort of cache, my knowledge of such things is not deep enough to come to a right conclusion.

Thanks!

Message has been deleted

Vlad Shelest

unread,
Oct 5, 2014, 4:39:45 AM10/5/14
to jackso...@googlegroups.com

I found VisitorContext class that does the evil inside SchemaFactoryWrapper, don't see a way to override it as its methods are static...

Sandeep Jadhav

unread,
Jul 26, 2017, 2:05:14 AM7/26/17
to jackson-user
did you get any solution for this?
Reply all
Reply to author
Forward
0 new messages