本文整理汇总了Java中com.fasterxml.jackson.module.jsonSchema.JsonSchema类的典型用法代码示例。如果您正苦于以下问题:Java JsonSchema类的具体用法?Java JsonSchema怎么用?Java JsonSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonSchema类属于com.fasterxml.jackson.module.jsonSchema包,在下文中一共展示了JsonSchema类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: SalesforceMetadataAdapterTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public SalesforceMetadataAdapterTest() {
final Map<String, JsonSchema> objectProperties = new HashMap<>();
objectProperties.put("simpleProperty", new StringSchema());
objectProperties.put("anotherProperty", new NumberSchema());
final StringSchema uniqueProperty1 = new StringSchema();
uniqueProperty1.setDescription("idLookup,autoNumber");
uniqueProperty1.setTitle("Unique property 1");
final StringSchema uniqueProperty2 = new StringSchema();
uniqueProperty2.setDescription("calculated,idLookup");
uniqueProperty2.setTitle("Unique property 2");
objectProperties.put("uniqueProperty1", uniqueProperty1);
objectProperties.put("uniqueProperty2", uniqueProperty2);
final ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setId("urn:jsonschema:org:apache:camel:component:salesforce:dto:SimpleObject");
objectSchema.setProperties(objectProperties);
payload = new ObjectSchema();
payload.setOneOf(Collections.singleton(objectSchema));
}
开发者ID:syndesisio,项目名称:syndesis-verifier,代码行数:24,代码来源:SalesforceMetadataAdapterTest.java
示例2: adaptTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Test
public void adaptTest() throws IOException {
SqlStoredConnectorMetaDataExtension ext = new SqlStoredConnectorMetaDataExtension();
Map<String,Object> parameters = new HashMap<>();
for (final String name: properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".")+1), properties.getProperty(name));
}
Optional<MetaData> metadata = ext.meta(parameters);
SqlStoredMetadataAdapter adapter = new SqlStoredMetadataAdapter();
SyndesisMetadata<JsonSchema> syndesisMetaData = adapter.adapt(parameters, metadata.get());
ObjectMapper mapper = new ObjectMapper();
String expectedListOfProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8);
String actualListOfProcedures = (mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData));
assertEquals(expectedListOfProcedures, actualListOfProcedures);
parameters.put("procedureName", "DEMO_ADD");
SyndesisMetadata<JsonSchema> syndesisMetaData2 = adapter.adapt(parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/demo_add_metadata.json"), StandardCharsets.UTF_8);
String actualMetadata = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata);
}
开发者ID:syndesisio,项目名称:syndesis-verifier,代码行数:25,代码来源:SqlStoredMetadataAdapterTest.java
示例3: getSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getSchemma(Class<?> clazz) {
ObjectMapper mapper = new ObjectMapper();
Optional<JsonSchema> schema = Optional.empty();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
Optional<Class<?>> realClazz = ReflectionUtils.getGenericClass(clazz);
boolean iterable = Iterable.class.isAssignableFrom(clazz) && realClazz.isPresent();
if (iterable) {
clazz = realClazz.get();
}
try {
mapper.acceptJsonFormatVisitor(clazz, visitor);
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
schema = Optional.ofNullable(schemaGen.generateSchema(clazz));
if (iterable) {
// TODO: decirle que es una collection
}
} catch (JsonMappingException e) {
LOGGER.error("Se produjo un error al crear el JsonSchemma para la clase {}", clazz.getSimpleName(), e);
}
return schema;
}
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:23,代码来源:JsonSchemmaUtils.java
示例4: getResponseSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getResponseSchemma(Method m, Class<?> parametrizedClass) {
Optional<JsonSchema> schemma = Optional.empty();
// obtengo el tipo real de retorno por si es generic
Optional<Type> returnType = ReflectionUtils.getRealType(m.getGenericReturnType(), parametrizedClass);
if (returnType.isPresent()) {
// el return type puede ser una colleccion para eso obtengo la clase real del
// parametro a traves de reflection utils
Optional<Class<?>> realClass = ReflectionUtils.getClass(returnType.get());
if (realClass.isPresent()) {
if (Iterable.class.isAssignableFrom(realClass.get())) {
// si es una collection tengo que saber si es generic, para eso le pido la clase
// al return type
if (ParameterizedType.class.isAssignableFrom(returnType.get().getClass()))
returnType = ReflectionUtils.getGenericType((ParameterizedType) returnType.get());
}
schemma = getSchemma(ReflectionUtils.getClass(returnType.orElse(null)).orElse(realClass.get()));
} else {
LOGGER.error("No existe una real class para: {}", returnType);
}
}
return schemma;
}
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:24,代码来源:JsonSchemmaUtils.java
示例5: getRequestSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private static Optional<JsonSchema> getRequestSchemma(Method m, Class<?> controller) {
List<Parameter> p = ReflectionUtils.getParametersBody(m);
Optional<JsonSchema> schemma = Optional.empty();
if (!p.isEmpty()) {
Optional<Type> t = ReflectionUtils.getRealType(p.get(0).getParameterizedType(), controller);
if (t.isPresent()) {
Optional<Class<?>> c = ReflectionUtils.getClass(t.get());
if (c.isPresent()) {
schemma = getSchemma(c.get());
} else {
schemma = getSchemma(t.getClass());
}
} else {
schemma = getSchemma(ReflectionUtils.getClass(p.get(0).getParameterizedType()));
}
}
return schemma;
}
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:19,代码来源:JsonSchemmaUtils.java
示例6: getPaths
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public List<String> getPaths(final String kind, final String type, final String specification,
final Optional<byte[]> exemplar) {
final ObjectSchema schema;
try {
schema = MAPPER.readerFor(ObjectSchema.class).readValue(specification);
} catch (final IOException e) {
LOG.warn(
"Unable to parse the given JSON schema, increase log level to DEBUG to see the schema being parsed");
LOG.debug(specification);
return Collections.emptyList();
}
final Map<String, JsonSchema> properties = schema.getProperties();
final List<String> paths = new ArrayList<>();
fetchPaths(null, paths, properties);
return paths;
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:22,代码来源:JsonSchemaInspector.java
示例7: fetchPaths
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) {
for (final Entry<String, JsonSchema> entry : properties.entrySet()) {
final JsonSchema subschema = entry.getValue();
String path;
final String key = entry.getKey();
if (context == null) {
path = key;
} else {
path = context + "." + key;
}
if (subschema.isValueTypeSchema()) {
paths.add(path);
} else if (subschema.isObjectSchema()) {
fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties());
}
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:20,代码来源:JsonSchemaInspector.java
示例8: adaptForSqlTest
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Test
public void adaptForSqlTest() throws IOException {
SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension();
Map<String,Object> parameters = new HashMap<>();
for (final String name: properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".")+1), properties.getProperty(name));
}
parameters.put("query", "SELECT * FROM NAME WHERE ID=:#id");
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataAdapter adapter = new SqlMetadataAdapter();
ObjectMapper mapper = new ObjectMapper();
SyndesisMetadata<JsonSchema> syndesisMetaData2 = adapter.adapt("sql-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_metadata.json"), StandardCharsets.UTF_8);
String actualMetadata = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata);
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:21,代码来源:SqlMetadataAdapterTest.java
示例9: customizeSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
Optional.ofNullable(property.getAnnotation(Password.class)).ifPresent(annotation -> {
if (annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
});
}
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:18,代码来源:PasswordSchemaDecorator.java
示例10: customizeSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
TextField annotation = property.getAnnotation(TextField.class);
if (annotation != null) {
if (annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
}
}
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:19,代码来源:TextFieldSchemaDecorator.java
示例11: findRefs
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void findRefs(JsonSchema schema, Map<String, JsonSchema> refs, Set<String> referenced) {
addRef(schema, refs);
if (schema instanceof ReferenceSchema) {
referenced.add(schema.get$ref());
} else if (schema.isArraySchema()) {
ArraySchema as = schema.asArraySchema();
if (as.getItems() != null) {
if (as.getItems().isSingleItems()) {
findRefs(as.getItems().asSingleItems().getSchema(), refs, referenced);
} else if (as.getItems().isArrayItems()) {
ArrayItems items = as.getItems().asArrayItems();
for (JsonSchema item : items.getJsonSchemas()) {
findRefs(item, refs, referenced);
}
} else {
throw new UnsupportedOperationException(as.getItems().toString());
}
}
} else if (schema.isObjectSchema()) {
ObjectSchema os = schema.asObjectSchema();
for (JsonSchema value : os.getProperties().values()) {
findRefs(value, refs, referenced);
}
}
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:Doc.java
示例12: objectExample
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void objectExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced, String id) {
sb.append("{");
if (referenced.contains(id)) {
shortId(sb, schema);
}
ObjectSchema os = schema.asObjectSchema();
if (os.getProperties().isEmpty()) {
AdditionalProperties additionalProperties = os.getAdditionalProperties();
if (additionalProperties instanceof SchemaAdditionalProperties) {
sb.append("\n").append(indent).append(" ").append("abc").append(": ");
example(sb, maxlength, indent + " ", ((SchemaAdditionalProperties) additionalProperties).getJsonSchema(), refs, followed, referenced);
sb.append(", ...");
}
}
Map<String, JsonSchema> props = new TreeMap<>(os.getProperties());
for (Entry<String, JsonSchema> entry : props.entrySet()) {
sb.append("\n").append(indent).append(" ").append(entry.getKey()).append(": ");
example(sb, maxlength, indent + " ", entry.getValue(), refs, followed, referenced);
sb.append(",");
}
sb.append("\n").append(indent).append("}");
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:Doc.java
示例13: arrayExample
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
private void arrayExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced) {
sb.append("[\n").append(indent).append(" ");
ArraySchema as = schema.asArraySchema();
if (as.getItems() == null) {
sb.append(" ... ]");
} else if (as.getItems().isSingleItems()) {
example(sb, maxlength, indent + " ", as.getItems().asSingleItems().getSchema(), refs, followed, referenced);
sb.append(",\n").append(indent).append(" ...\n").append(indent).append("]");
} else if (as.getItems().isArrayItems()) {
ArrayItems items = as.getItems().asArrayItems();
for (JsonSchema item : items.getJsonSchemas()) {
sb.append("\n").append(indent);
example(sb, maxlength, indent + " ", item, refs, followed, referenced);
sb.append(",");
}
sb.append("]");
} else {
throw new UnsupportedOperationException(as.getItems().toString());
}
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:22,代码来源:Doc.java
示例14: convertClassToJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
/**
* Uses Jackson object mappers to convert an ajaxcommandparameter annotated type into its
* JSONSchema representation.
* If Javadoc is supplied, this will be injected as comments
*
* @param clazz
* The Class to convert
* @param responseDescription
* The javadoc description supplied if available
* @param javaDocStore
* The Entire java doc store available
* @return A string containing the Json Schema
*/
public static String convertClassToJsonSchema(ApiParameterMetadata clazz, String responseDescription,
JavaDocStore javaDocStore) {
if (clazz == null || clazz.equals(Void.class)) {
return "{}";
}
try {
ObjectMapper m = new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JsonSchema jsonSchema = extractSchemaInternal(clazz.getType(), clazz.getGenericType(), responseDescription,
javaDocStore, m);
return m.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:33,代码来源:SchemaHelper.java
示例15: getSchemaForHtml
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public Optional<String> getSchemaForHtml(ObjectMapper objectMapper, Class modelClass, Function<String, String> classNameToHyperlink) throws IOException {
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
visitor.setVisitorContext(new VisitorContextWithoutSchemaInlining() {
public String javaTypeToUrn(JavaType jt) {
return jt.toCanonical();
}
});
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(modelClass), visitor);
JsonSchema jsonSchema = visitor.finalSchema();
JsonNode schemaNode = objectMapper.convertValue(jsonSchema, JsonNode.class);
if (schemaNode.equals(objectMapper.readTree("{\"type\":\"any\"}"))) {
return Optional.empty();
}
String result = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schemaNode);
result = StringEscapeUtils.escapeHtml3(result);
result = activateRefLinks(result, classNameToHyperlink);
return Optional.of(result);
}
开发者ID:dnault,项目名称:therapi-json-rpc,代码行数:23,代码来源:JsonSchemaProvider.java
示例16: getSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
protected void getSchema(Class<?> clazz, ObjectNode schema, ArrayNode form) throws JsonMappingException {
SchemaFactoryWrapper factoryWrapper = new SchemaFactoryWrapper();
JsonSubTypes subtype = clazz.getAnnotation(JsonSubTypes.class);
if (subtype != null) {
doForSubtype(factoryWrapper, schema, form, subtype);
} else {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(clazz), factoryWrapper);
JsonSchema jsonSchema = factoryWrapper.finalSchema();
jsonSchema.setId(null);
String title = clazz.getSimpleName().replaceAll("\\.", "_");
jsonSchema.asObjectSchema().setTitle(title);
iterateOnProperties(jsonSchema.asObjectSchema().getProperties());
schema.putPOJO(title, jsonSchema);
}
}
开发者ID:Treydone,项目名称:mandrel,代码行数:19,代码来源:SchemaGenerator.java
示例17: iterateOnProperties
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public void iterateOnProperties(Map<String, JsonSchema> properties) {
properties.remove("type");
for (Entry<String, JsonSchema> entry : properties.entrySet()) {
entry.getValue().setId(null);
if (entry.getValue().isSimpleTypeSchema()) {
entry.getValue().asSimpleTypeSchema().setTitle(entry.getKey());
if (entry.getValue().isObjectSchema()) {
iterateOnProperties(entry.getValue().asObjectSchema().getProperties());
}
if (entry.getValue().isArraySchema()) {
JsonSchema arraySchema = entry.getValue().asArraySchema().getItems().asSingleItems().getSchema();
arraySchema.setId(null);
if (arraySchema.isSimpleTypeSchema()) {
arraySchema.asSimpleTypeSchema().setTitle(entry.getKey().substring(0, entry.getKey().length() - 1));
if (arraySchema.isObjectSchema()) {
iterateOnProperties(arraySchema.asObjectSchema().getProperties());
}
}
}
}
}
}
开发者ID:Treydone,项目名称:mandrel,代码行数:23,代码来源:SchemaGenerator.java
示例18: getJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public JsonSchema getJsonSchema(String className) throws IOException {
Class<?> foundClass = null;
for (String searchPackage : describeModelSearchPackages) {
LOG.debug(String.format("Search className %s in package %s.", className, searchPackage));
try{
boolean wasNull = foundClass == null;
foundClass = Class.forName(searchPackage + "." + className);
if (!wasNull) {
LOG.error(String.format("Modelname %s exists in multiple packages! Last one will win.", className));
}
} catch (ClassNotFoundException e){
//not in this package, try another
}
}
if (foundClass == null) {
LOG.warn(String.format("No class found for describing modelname %s", className));
return null;
}
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(objectMapper);
JsonSchema schema = schemaGen.generateSchema(foundClass);
return schema;
}
开发者ID:terrestris,项目名称:shogun2,代码行数:27,代码来源:ModelDescriptionService.java
示例19: getDocument
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
public static Document getDocument(Class<? extends Servlet> servletClass, String name)
throws IllegalAccessException, InstantiationException, JsonMappingException,
HandlerFactory.HandlerInitException {
if (document == null) {
Map<String, JsonSchema> models = new HashMap<>();
for (String pkg : servletClass.newInstance().getPackageNames()) {
Reflections reflections = new Reflections(pkg);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Model.class);
for (Class<?> c : classes) {
JsonSchema schema = Document.toJsonSchema(c);
models.put(schema.getId(), schema);
}
}
document = new Document();
document.models = models;
document.name = name;
for (Class<? extends Handler> handlerClass : HandlerMeta.annotationMapper.handlers) {
getOneApi(document, null, null, handlerClass, servletClass);
}
}
return document;
}
开发者ID:wb14123,项目名称:bard,代码行数:23,代码来源:APIDocFilter.java
示例20: generateSearchQueryInstructionJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; //导入依赖的package包/类
@Override
public String generateSearchQueryInstructionJsonSchema() {
String jsonSchemaAsString = null;
try {
ObjectMapper mapper = getObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(
mapper.constructType(SearchQueryInstruction.class), visitor);
JsonSchema schema = visitor.finalSchema();
jsonSchemaAsString = mapper.writeValueAsString(schema);
} catch (JsonProcessingException e) {
throw new RuntimeException("Error occured generating json schema!",
e);
}
return jsonSchemaAsString;
}
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:17,代码来源:GenerateSearchAnalyticsDataImpl.java
注:本文中的com.fasterxml.jackson.module.jsonSchema.JsonSchema类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论