本文整理汇总了Java中com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator类的典型用法代码示例。如果您正苦于以下问题:Java JsonSchemaGenerator类的具体用法?Java JsonSchemaGenerator怎么用?Java JsonSchemaGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonSchemaGenerator类属于com.fasterxml.jackson.module.jsonSchema包,在下文中一共展示了JsonSchemaGenerator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getSchemma
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的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
示例2: getJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的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
示例3: generateBaseExtensionDefinition
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
@Test
@Ignore("Used to generate the initial extension definition")
public void generateBaseExtensionDefinition() throws Exception {
ObjectMapper mapper = Json.mapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
com.fasterxml.jackson.module.jsonSchema.JsonSchema schema = schemaGen.generateSchema(Extension.class);
System.out.println(mapper.writeValueAsString(schema));
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:10,代码来源:ExtensionSchemaValidationTest.java
示例4: shouldSerializeJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
@Test
public void shouldSerializeJsonSchema() throws Exception {
JsonSchemaGenerator generator = new JsonSchemaGenerator(unit);
JsonSchema jsonSchema = generator.generateSchema(CurrencyUnit.class);
final String actual = unit.writeValueAsString(jsonSchema);
final String expected = "{\"type\":\"string\"}";
assertThat(actual, is(expected));
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:10,代码来源:CurrencyUnitSchemaSerializerTest.java
示例5: shouldSerializeJsonSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
@Test
public void shouldSerializeJsonSchema() throws Exception {
ObjectMapper unit = unit(module());
JsonSchemaGenerator generator = new JsonSchemaGenerator(unit);
JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class);
final String actual = unit.writeValueAsString(jsonSchema);
final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" +
"{\"amount\":{\"type\":\"number\",\"required\":true}," +
"\"currency\":{\"type\":\"string\",\"required\":true}," +
"\"formatted\":{\"type\":\"string\"}}}";
assertThat(actual, is(expected));
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:14,代码来源:MonetaryAmountSchemaSerializerTest.java
示例6: shouldSerializeJsonSchemaWithCustomFieldNames
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
@Test
public void shouldSerializeJsonSchemaWithCustomFieldNames() throws Exception {
ObjectMapper unit = unit(module().withAmountFieldName("value")
.withCurrencyFieldName("unit")
.withFormattedFieldName("pretty"));
JsonSchemaGenerator generator = new JsonSchemaGenerator(unit);
JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class);
final String actual = unit.writeValueAsString(jsonSchema);
final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" +
"{\"value\":{\"type\":\"number\",\"required\":true}," +
"\"unit\":{\"type\":\"string\",\"required\":true}," +
"\"pretty\":{\"type\":\"string\"}}}";
assertThat(actual, is(expected));
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:16,代码来源:MonetaryAmountSchemaSerializerTest.java
示例7: shouldSerializeJsonSchemaWithQuotedDecimalNumbers
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
@Test
public void shouldSerializeJsonSchemaWithQuotedDecimalNumbers() throws Exception {
ObjectMapper unit = unit(module().withQuotedDecimalNumbers());
JsonSchemaGenerator generator = new JsonSchemaGenerator(unit);
JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class);
final String actual = unit.writeValueAsString(jsonSchema);
final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" +
"{\"amount\":{\"type\":\"string\",\"required\":true}," +
"\"currency\":{\"type\":\"string\",\"required\":true}," +
"\"formatted\":{\"type\":\"string\"}}}";
assertThat(actual, is(expected));
}
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:14,代码来源:MonetaryAmountSchemaSerializerTest.java
示例8: generate
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
public UiForm generate(Class<? extends Serializable> formDto) throws JsonMappingException {
Field[] declaredFields = formDto.getDeclaredFields();
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = initSchemaGen(mapper);
JsonSchema schema = generateSchema(formDto, schemaGen);
Map<Field, JsonNode> nodes = initFieldsFormDefinition(mapper, declaredFields);
Map<Field, JsonNode> sortedNodes = reorderFieldsBasedOnIndex(nodes);
handlerGroupedFields(mapper, declaredFields, sortedNodes);
Optional<ObjectNode> tabbedFields = Optional
.ofNullable(handleTabbedFields(mapper, declaredFields, sortedNodes));
ArrayNode formDefinition = mapper.createArrayNode();
tabbedFields.ifPresent(formDefinition::add);
sortedNodes.entrySet().stream().forEach(nodesElement -> formDefinition.add(nodesElement.getValue()));
handleActionsAnnotation(mapper, formDto, formDefinition);
return new UiForm(schema, formDefinition);
}
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:25,代码来源:UiFormSchemaGenerator.java
示例9: generateSchema
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
private JsonSchema generateSchema(Class<? extends Serializable> formDto, JsonSchemaGenerator schemaGen)
throws JsonMappingException {
return schemaGen.generateSchema(formDto);
}
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:5,代码来源:UiFormSchemaGenerator.java
示例10: initSchemaGen
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
private JsonSchemaGenerator initSchemaGen(ObjectMapper mapper) {
return new JsonSchemaGenerator(mapper, new CustomSchemaFactoryWrapper());
}
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:4,代码来源:UiFormSchemaGenerator.java
示例11: initSchemaMapper
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; //导入依赖的package包/类
/**
* Setup the JSON schema generator.
*/
private static void initSchemaMapper() {
ObjectMapper mapper = new ObjectMapper();
// configure mapper, if necessary, then create schema generator
schemaGen = new JsonSchemaGenerator(mapper);
}
开发者ID:gentics,项目名称:mesh,代码行数:9,代码来源:JsonUtil.java
注:本文中的com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论