• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JsonSchemaGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SelectByExampleWithoutBLOBsMethodGenerator类代码示例发布时间:2022-05-22
下一篇:
Java DefaultConfig类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap