
Android 是一个专门针对移动设备的软件集,它包括一个操作系统,中间件和一些重要的应用程序。Beta版的 Android SDK 提供了在Android平台上使用JaVa语言进行Android应用开发必须的工具和API接口。 特性 应用程序框架 支持组件的重用与替换 Dalvik 虚拟机 专为移动设备优化 集成的浏览器 基于开源的WebKit 引擎 优化的图形库 包括定制的2D图形库,3D图形库基于
0
JSON Schema是一种基于JSON格式的规范,用于定义JSON数据的结构。JsonSchema类可以为给定应用程序所需的JSON数据提供合同,并指导如何与其进行交互。JsonSchema可以定义JSON数据的验证、文档、超链接导航和交互控制。我们可以使用JsonSchemaGenerator的generateSchema()方法生成JSON模式,该类封装了JSON模式生成功能。
public JsonSchema generateSchema(Class<T><!--?--> type) throws com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
import java.util.List;
public class JSONSchemaTest {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper jacksonObjectMapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(jacksonObjectMapper);
JsonSchema schema = schemaGen.generateSchema(Person.class);
String schemaString = jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
System.out.println(schemaString);
}
}
// Person class
class Person {
private String name;
private int age;
private List<String> courses;
private Address address;
public String getName() {
return name;
}
public int getAge(){
return age;
}
public List<String> getCourse() {
return courses;
}
public Address getAddress() {
return address;
}
}
// Address class
class Address {
private String firstLine;
private String secondLine;
private String thirdLine;
public String getFirstLine() {
return firstLine;
}
public String getSecondLine() {
return secondLine;
}
public String getThirdLine() {
return thirdLine;
}
}{
"type" : "object",
"id" : "urn:jsonschema:Person",
"properties" : {
"name" : {
"type" : "string"
},
"age" : {
"type" : "integer"
},
"address" : {
"type" : "object",
"id" : "urn:jsonschema:Address",
"properties" : {
"firstLine" : {
"type" : "string"
},
"secondLine" : {
"type" : "string"
},
"thirdLine" : {
"type" : "string"
}
}
},
"course" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
}以上就是在Java中使用Jackson支持JSON Schema吗?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号