当前位置: 首页 > news >正文

国际域名的外贸网站设计方案格式模板

国际域名的外贸网站,设计方案格式模板,frontpage网页制作成品,深圳网站制作必找祥奔科技在本文中#xff0c;我演示了一种从XML Schema #xff08;XSD#xff09;生成JSON Schema的 方法 。 在概述从XML Schema创建JSON Schema的方法的同时#xff0c;本文还演示了JAXB实现的用法#xff08;与JDK 9捆绑在一起的xjc版本2.2.12-b150331.1824 [build 1.9.0-ea-b… 在本文中我演示了一种从XML Schema XSD生成JSON Schema的 方法 。 在概述从XML Schema创建JSON Schema的方法的同时本文还演示了JAXB实现的用法与JDK 9捆绑在一起的xjc版本2.2.12-b150331.1824 [build 1.9.0-ea-b68]和JSON / Java绑定实现的说明 杰克逊 2.5.4。 从XSD生成JSON模式的这种方法的步骤可以概括为 应用JAXB的xjc编译器从XML SchemaXSD生成Java类。 应用Jackson来从JAXB生成的Java类生成JSON模式。 使用JAXB的xjc从XSD生成Java类 为了便于讨论我将使用我先前的博客文章A JAXB Nuance字符串与枚举受限XSD字符串中的枚举使用的简单Food.xsd 。 为了方便起见我在此处重现了该简单模式但没有特定于先前博客文章的XML注释 Food.xsd ?xml version1.0 encodingutf-8? xs:schema xmlns:xshttp://www.w3.org/2001/XMLSchemaxmlns:dustinhttp://marxsoftware.blogspot.com/foodxmltargetNamespacehttp://marxsoftware.blogspot.com/foodxmlelementFormDefaultqualifiedattributeFormDefaultunqualifiedxs:element nameFoodxs:complexTypexs:sequencexs:element nameVegetable typedustin:Vegetable /xs:element refdustin:Fruit /xs:element nameDessert typedustin:Dessert //xs:sequence/xs:complexType/xs:elementxs:simpleType nameVegetablexs:restriction basexs:stringxs:enumeration valueCarrot/xs:enumeration valueSquash/xs:enumeration valueSpinach/xs:enumeration valueCelery//xs:restriction/xs:simpleTypexs:element nameFruitxs:simpleTypexs:restriction basexs:stringxs:enumeration valueWatermelon/xs:enumeration valueApple/xs:enumeration valueOrange/xs:enumeration valueGrape//xs:restriction/xs:simpleType/xs:elementxs:simpleType nameDessertxs:restriction basexs:stringxs:enumeration valuePie/xs:enumeration valueCake/xs:enumeration valueIce Cream//xs:restriction/xs:simpleType/xs:schema 使用JDK提供的JAXB实现提供的xjc命令行工具很容易生成与此XSD对应的Java类。 下一个屏幕快照使用以下命令显示了此过程 xjc -d jaxb。\ Food.xsd 这个简单的命令生成与提供的Food.xsd相对应的Java类并将这些类放置在指定的“ jaxb”子目录中。 用Jackson从JAXB生成的类生成JSON 使用现在可用的JAXB生成的类可以将Jackson应用于这些类以从Java类生成JSON。 杰克逊在其主门户页面上被描述为“一个用于处理的多功能Java库”“受到Java平台可用的XML工具的质量和多样性的启发。” Jackson的存在以及类似的框架和库似乎是Oracle从Java SE 9中 删除 JEP 198 “轻型JSON API”的原因之一。 [值得注意的是 Java EE 7已经通过其JSR 353 “与JSON处理有关的Java API”的实现实现了内置的JSON支持 而该JSR 353与JEP 198无关。 将Jackson应用于从我们的JAXB生成的Java类生成JSON的第一步就是获取并配置Jackson的ObjectMapper类的实例。 下一个代码清单显示了实现此目的的一种方法。 获取和配置用于JAXB序列化/反序列化的Jackson ObjectMapper /*** Create instance of ObjectMapper with JAXB introspector* and default type factory.** return Instance of ObjectMapper with JAXB introspector* and default type factory.*/ private ObjectMapper createJaxbObjectMapper() {final ObjectMapper mapper new ObjectMapper();final TypeFactory typeFactory TypeFactory.defaultInstance();final AnnotationIntrospector introspector new JaxbAnnotationIntrospector(typeFactory);// make deserializer use JAXB annotations (only)mapper.getDeserializationConfig().with(introspector);// make serializer use JAXB annotations (only)mapper.getSerializationConfig().with(introspector);return mapper; } 上面的代码清单演示了如何获取Jackson的ObjectMapper实例并将其配置为使用默认类型的工厂和面向JAXB的注释自检器。 在实例化并正确配置了Jackson ObjectMapper情况下很容易使用该ObjectMapper实例从生成的JAXB类生成JSON。 下一个代码清单中演示了使用不推荐使用的Jackson类JsonSchema实现此目的的一种方法。 使用不推荐使用的com.fasterxml.jackson.databind.jsonschema.JsonSchema类从Java类生成JSON /*** Write JSON Schema to standard output based upon Java source* code in class whose fully qualified package and class name* have been provided.** param mapper Instance of ObjectMapper from which to* invoke JSON schema generation.* param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/ private void writeToStandardOutputWithDeprecatedJsonSchema(final ObjectMapper mapper, final String fullyQualifiedClassName) {try{final JsonSchema jsonSchema mapper.generateJsonSchema(Class.forName(fullyQualifiedClassName));out.println(jsonSchema);}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);} } 上面清单中的代码实例化获取提供的Java类的类定义在我的示例中由JAXB xjc编译器生成的最高级别的Food类并将对该JAXB生成的类的引用传递给ObjectMapper的generateJsonSchemaClass 方法。 不推荐使用的JsonSchema类的toString实现非常有用并且可以轻松写出从JAXB生成的类生成的JSON。 为了进行演示我将演示驱动程序作为mainString []函数提供。 在下一个代码清单中提供了该函数以及到目前为止的整个类包括上面显示的方法。 JsonGenerationFromJaxbClasses.java版本1 package dustin.examples.jackson;import com.fasterxml.jackson.databind.AnnotationIntrospector; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;import com.fasterxml.jackson.databind.jsonschema.JsonSchema;import static java.lang.System.out; import static java.lang.System.err;/*** Generates JavaScript Object Notation (JSON) from Java classes* with Java API for XML Binding (JAXB) annotations.*/ public class JsonGenerationFromJaxbClasses {/*** Create instance of ObjectMapper with JAXB introspector* and default type factory.** return Instance of ObjectMapper with JAXB introspector* and default type factory.*/private ObjectMapper createJaxbObjectMapper(){final ObjectMapper mapper new ObjectMapper();final TypeFactory typeFactory TypeFactory.defaultInstance();final AnnotationIntrospector introspector new JaxbAnnotationIntrospector(typeFactory);// make deserializer use JAXB annotations (only)mapper.getDeserializationConfig().with(introspector);// make serializer use JAXB annotations (only)mapper.getSerializationConfig().with(introspector);return mapper;}/*** Write out JSON Schema based upon Java source code in* class whose fully qualified package and class name have* been provided.** param mapper Instance of ObjectMapper from which to* invoke JSON schema generation.* param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/private void writeToStandardOutputWithDeprecatedJsonSchema(final ObjectMapper mapper, final String fullyQualifiedClassName){try{final JsonSchema jsonSchema mapper.generateJsonSchema(Class.forName(fullyQualifiedClassName));out.println(jsonSchema);}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);}}/*** Accepts the fully qualified (full package) name of a* Java class with JAXB annotations that will be used to* generate a JSON schema.** param arguments One argument expected: fully qualified* package and class name of Java class with JAXB* annotations.*/public static void main(final String[] arguments){if (arguments.length 1){err.println(Need to provide the fully qualified name of the highest-level Java class with JAXB annotations.);System.exit(-1);}final JsonGenerationFromJaxbClasses instance new JsonGenerationFromJaxbClasses();final String fullyQualifiedClassName arguments[0];final ObjectMapper objectMapper instance.createJaxbObjectMapper();instance.writeToStandardOutputWithDeprecatedJsonSchema(objectMapper, fullyQualifiedClassName);} } 要针对基于Food.xsd的JAXB的xjc生成的Java类运行此相对通用的代码我需要提供最高级别生成的类的标准软件包名称和类名称。 在这种情况下这就是com.blogspot.marxsoftware.foodxml.Food 程序包名称基于XSD的名称空间因为在运行xjc时我没有明确覆盖它。 当我使用完全限定的类名以及类路径上的JAXB类和Jackson库运行上述代码时我看到以下JSON写入了标准输出。 生成的JSON {type:object,properties:{vegetable:{type:string,enum:[CARROT,SQUASH,SPINACH,CELERY]},fruit:{type:string},dessert:{type:string,enum:[PIE,CAKE,ICE_CREAM]}}} 人类包括许多开发人员比打印的JSON更喜欢漂亮的打印 。 我们可以调整演示类的方法writeToStandardOutputWithDeprecatedJsonSchema(ObjectMapper, String) 如下所示以写出缩进的JSON 以更好地反映其层次结构性质。 接下来显示此修改的方法。 修改了writeToStandardOutputWithDeprecatedJsonSchemaObjectMapperString以写入缩进的JSON /*** Write out indented JSON Schema based upon Java source* code in class whose fully qualified package and class* name have been provided.** param mapper Instance of ObjectMapper from which to* invoke JSON schema generation.* param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/ private void writeToStandardOutputWithDeprecatedJsonSchema(final ObjectMapper mapper, final String fullyQualifiedClassName) {try{final JsonSchema jsonSchema mapper.generateJsonSchema(Class.forName(fullyQualifiedClassName));out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);}catch (JsonProcessingException jsonEx){err.println(Unable to process JSON: jsonEx);} } 当我使用此修改后的方法再次运行演示类时JSON输出在美学上更加令人愉悦 生成带有缩进通信层次结构的JSON {type : object,properties : {vegetable : {type : string,enum : [ CARROT, SQUASH, SPINACH, CELERY ]},fruit : {type : string},dessert : {type : string,enum : [ PIE, CAKE, ICE_CREAM ]}} } 我在这篇文章中一直在使用Jackson 2.5.4。 com.fasterxml.jackson. databind .jsonschema.JsonSchema类com.fasterxml.jackson. databind .jsonschema.JsonSchema 该版本不建议使用com.fasterxml.jackson. databind .jsonschema.JsonSchema 并带有以下注释“从2.2开始我们建议使用外部JSON Schema生成器模块 。” 鉴于此我现在看一下使用新的首选方法 Jackson JSON Schema Module方法。 最显著的变化是使用JsonSchema在类com.fasterxml.jackson.module.jsonSchema包而不是使用JsonSchema在类com.fasterxml.jackson.databind.jsonschema包。 获取这些不同版本的JsonSchema类的实例的方法也不同。 下一个代码清单演示了如何使用更新的首选方法从Java类生成JSON。 使用Jackson的更新和首选com.fasterxml.jackson.module.jsonSchema.JsonSchema /*** Write out JSON Schema based upon Java source code in* class whose fully qualified package and class name have* been provided. This method uses the newer module JsonSchema* class that replaces the deprecated databind JsonSchema.** param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/ private void writeToStandardOutputWithModuleJsonSchema(final String fullyQualifiedClassName) {final SchemaFactoryWrapper visitor new SchemaFactoryWrapper();final ObjectMapper mapper new ObjectMapper();try{mapper.acceptJsonFormatVisitor(mapper.constructType(Class.forName(fullyQualifiedClassName)), visitor);final com.fasterxml.jackson.module.jsonSchema.JsonSchema jsonSchema visitor.finalSchema();out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);}catch (JsonProcessingException jsonEx){err.println(Unable to process JSON: jsonEx);} } 下表将两个Jackson JsonSchema类的用法与左侧较早显示的已弃用方法进行了比较为该比较进行了一些调整并在右侧推荐了较新的方法。 两者针对要从其编写JSON的相同给定Java类生成相同的输出。 /*** Write out JSON Schema based upon Java source code in* class whose fully qualified package and class name have* been provided. This method uses the deprecated JsonSchema* class in the databind.jsonschema package* {see com.fasterxml.jackson.databind.jsonschema}.** param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/ private void writeToStandardOutputWithDeprecatedDatabindJsonSchema(final String fullyQualifiedClassName) {final ObjectMapper mapper new ObjectMapper();try{final com.fasterxml.jackson.databind.jsonschema.JsonSchema jsonSchema mapper.generateJsonSchema(Class.forName(fullyQualifiedClassName));out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);}catch (JsonProcessingException jsonEx){err.println(Unable to process JSON: jsonEx);} }/*** Write out JSON Schema based upon Java source code in* class whose fully qualified package and class name have* been provided. This method uses the newer module JsonSchema* class that replaces the deprecated databind JsonSchema.** param fullyQualifiedClassName Name of Java class upon* which JSON Schema will be extracted.*/ private void writeToStandardOutputWithModuleJsonSchema(final String fullyQualifiedClassName) {final SchemaFactoryWrapper visitor new SchemaFactoryWrapper();final ObjectMapper mapper new ObjectMapper();try{mapper.acceptJsonFormatVisitor(mapper.constructType(Class.forName(fullyQualifiedClassName)), visitor);final com.fasterxml.jackson.module.jsonSchema.JsonSchema jsonSchema visitor.finalSchema();out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));}catch (ClassNotFoundException cnfEx){err.println(Unable to find class fullyQualifiedClassName);}catch (JsonMappingException jsonEx){err.println(Unable to map JSON: jsonEx);}catch (JsonProcessingException jsonEx){err.println(Unable to process JSON: jsonEx);} } 这篇博客文章展示了两种方法这些方法使用由Jackson提供的名称为JsonSchema的类的不同版本来基于从具有JAXB的xjc的XSD生成的Java类编写JSON。 本文中演示的整个过程是一种从XML Schema生成JSON Schema的方法。 翻译自: https://www.javacodegeeks.com/2015/06/generating-json-schema-from-xsd-with-jaxb-and-jackson.html
http://wiki.neutronadmin.com/news/43587/

相关文章:

  • 河南专业网站建设公司健身房网站模板
  • 莆田建设网站建站订货网站怎么做
  • 站内推广和站外推广的区别网站ping怎么做
  • 如何利用影视网站做cpaphp网站开发实例视频
  • 商城网站建设如何交谈易点科技
  • 如何设计产品网站建设wordpress 发评论代码
  • 怎样看网站是谁做的网站备案网站要有内容吗
  • python 做下载网站怎么样做团购网站
  • layui做网站前端徐州百度推广
  • 昆山建设局网站查预售如何快速收录一个网站的信息
  • 有哪些做数据分析的网站做班级相册网站的目的意义
  • 阿里云国际站官网网站建设解析
  • 住房和城乡建设部的网站wordpress和drupal
  • 搜索视频 网站开发北海做网站的公司
  • 深圳电商网站制作没有公网ip建设网站
  • 北京大兴企业网站建设咨询百度小程序可以根据网站的要求做吗
  • lamp网站开发微软软件开发工程师待遇
  • 简单的招聘网站怎么做网站搜索工具
  • 河池个人网站开发公司深圳设计公司 电话
  • 网站域名跟谁买电商网站首页模板
  • 域名备案查询站长之家网络公司代理
  • 济南营销网站制作公司哪家好电子商务网站建设基础
  • 网站的seo后台怎么做实时新闻最新消息
  • 重庆网站建设就选承越勉费申请做网站
  • wordpress打开网站前动画商家免费入驻平台
  • 查公司查企业用什么网站ui培训班 千锋
  • 有没类似建设通的免费网站大型门户网站是这样炼成的源代码
  • 哪里有网站设计的公司网站前期定位
  • 壹佰网站建设怎么做推广让别人主动加我
  • 哈尔滨模版建站公司推荐怎么判断一个网站做的好不好