Jackson: generate schemas with references

前端 未结 3 951
忘掉有多难
忘掉有多难 2021-01-18 01:20

When using Jackson\'s JSON schema module, instead of serializing the complete graph I\'d like to stop whenever one of my model classes is encountered, and use the class nam

3条回答
  •  余生分开走
    2021-01-18 01:50

    You can use the HyperSchemaFactoryWrapper instead of SchemaFactoryWrapper. In this way you will get urn reference for nested entities:

    HyperSchemaFactoryWrapper visitor= new HyperSchemaFactoryWrapper();
    ObjectMapper mapper = objectMapperFactory.getMapper();
    mapper.acceptJsonFormatVisitor(mapper.constructType(Zoo.class), visitor);
    JsonSchema jsonSchema = visitor.finalSchema();
    
    System.out.println(mapper.writeValueAsString(jsonSchema));
    

提交回复
热议问题