/** * Method for visiting type hierarchy for given type, using specified visitor. *<p> * This method can be used for things like * generating <a href="http://json-schema.org/">JSON Schema</a> * instance for specified type. * * @param type Type to generate schema for (possibly with generic signature) * * @since 2.1 */ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor); }
import java.io.IOException; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; public class JacksonProgram { public static void main(String[] args) throws IOException { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(Entity.class, visitor); JsonSchema schema = visitor.finalSchema(); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema)); } }
mapper.acceptJsonFormatVisitor(mapper.constructType(type), visitor); final JsonSchema schema = visitor.finalSchema(); models.put(type.getSimpleName(), schema);
@GET @Path("{configClass}") @Produces(MoreMediaTypes.APPLICATION_SCHEMA_JSON) @ApiOperation(value = "Get JSON schema of configuration class") @Timed @RequiresPermissions(RestPermissions.CLUSTER_CONFIG_ENTRY_READ) public JsonSchema schema(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass) { final Class<?> cls = classFromName(configClass); if (cls == null) { throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\""); } final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(cls), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for configuration class " + configClass, e); } return visitor.finalSchema(); }
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) { final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName); if (provider == null) { throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName); } final RetentionStrategy retentionStrategy = provider.get(); final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e); } return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema()); } }
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) { final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName); if (provider == null) { throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName); } final RotationStrategy rotationStrategy = provider.get(); final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e); } return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema()); } }
objectMapper.acceptJsonFormatVisitor(objectClass, visitor); JsonSchema schema = visitor.finalSchema(); schemaDef = objectMapper.writeValueAsString(schema);
/** * Method for visiting type hierarchy for given type, using specified visitor. *<p> * This method can be used for things like * generating <a href="http://json-schema.org/">JSON Schema</a> * instance for specified type. * * @param type Type to generate schema for (possibly with generic signature) * * @since 2.1 */ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor); }
/** * Method for visiting type hierarchy for given type, using specified visitor. *<p> * This method can be used for things like * generating <a href="http://json-schema.org/">Json Schema</a> * instance for specified type. * * @param type Type to generate schema for (possibly with generic signature) * * @since 2.1 */ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor); }
/** * Method for visiting type hierarchy for given type, using specified visitor. *<p> * This method can be used for things like * generating <a href="http://json-schema.org/">Json Schema</a> * instance for specified type. * * @param type Type to generate schema for (possibly with generic signature) * * @since 2.1 */ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor); }
/** * Method for visiting type hierarchy for given type, using specified visitor. *<p> * This method can be used for things like * generating <a href="http://json-schema.org/">JSON Schema</a> * instance for specified type. * * @param type Type to generate schema for (possibly with generic signature) * * @since 2.1 */ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor); }
public class JacksonSchema { public static class ZKBean { @JsonPropertyDescription("This is a property description") public String anExample; public int anInt; } public static void main(String[] args) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(ZKBean.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); System.out.println(mapper .writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema)); } }
import java.io.IOException; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; public class JacksonProgram { public static void main(String[] args) throws IOException { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(Entity.class, visitor); JsonSchema schema = visitor.finalSchema(); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema)); } }
ObjectMapper m = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.acceptJsonFormatVisitor(m.constructType(Phone.class), visitor); JsonSchema jsonSchema = visitor.finalSchema(); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); mapper.writeValue(yamlFile, jsonSchema);
public class JacksonSchema1 { public static class Bean { public String name; public Date date; } public static void main(String[] args) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(mapper.constructType(Bean.class), visitor); JsonSchema jsonSchema = visitor.finalSchema(); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema)); } }
ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(mapper.constructType(YOURCLASS.class), visitor); JsonSchema jsonSchema = visitor.finalSchema(); String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
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));
Reflections reflections = new Reflections( new ConfigurationBuilder().setUrls( ClasspathHelper.forClassLoader(urlcl)). addClassLoader(urlcl)); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(JsonBean.class); ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); for (Class<?> clazz : annotated) { try { mapper.acceptJsonFormatVisitor(mapper.constructType(SampleBean.class), visitor); JsonSchema jsonSchema = visitor.finalSchema(); String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema); System.out.println(schemaString);
protected Response createModelResponse(Class clazz) { try { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(mapper.constructType(clazz), visitor); JsonSchema jsonSchema = visitor.finalSchema(); return createOkResponse(new QueryResult<>(clazz.toString(), 0, 1, 1, null, null, Collections.singletonList(jsonSchema))); } catch (Exception e) { return createErrorResponse(e); } }
private OutputColumns createOutputColumns(org.datacleaner.api.OutputColumns outCols) { OutputColumns outColsResult = new OutputColumns(); for (int i = 0; i < outCols.getColumnCount(); i++) { SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { ComponentHandler.mapper.acceptJsonFormatVisitor(outCols.getColumnType(i), visitor); } catch (JsonMappingException e) { throw new RuntimeException(e); } outColsResult.add(outCols.getColumnName(i), outCols.getColumnType(i), visitor.finalSchema()); } return outColsResult; }