JSONIX:获取属性的限制和默认值 [英] JSONIX: Get restrictions and default value for properties

查看:91
本文介绍了JSONIX:获取属性的限制和默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSONIX进行编组和解组XML文件。到目前为止它运作良好。我缺少的是获得默认值和限制的可能性,例如minOccours和maxOccours-Values。 JSONIX在某种程度上是否可行?

I am using JSONIX for marshalling and unmarshalling XML files. So far it works pretty well. What I am missing is the possibility to get default values and restrictions like minOccours and maxOccours-Values. Is this somehow possible with JSONIX?

这些属性:

    <xsd:sequence>
      <xsd:element name="inflowMin" type="framework:flowType" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="inflowMax" type="framework:flowType" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="unitOfFlowControl" type="framework:flowUnit" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="waterCosts" type="xsd:double" default="0.0"/>
    <xsd:attribute name="controllable" type="xsd:boolean" default="0"/>
    <xsd:attribute name="scalingOfControl" type="xsd:double" default="1.0" />

获取:

    propertyInfos: [{
        type: 'element',
        name: 'inflowMin',
        elementName: 'inflowMin',
        typeInfo: ...
    }, {
        type: 'element',
        name: 'inflowMax',
        elementName: 'inflowMax',
        typeInfo: ...
    }, {
        type: 'element',
        name: 'unitOfFlowControl',
        elementName: 'unitOfFlowControl',
        typeInfo: 'String'
    }, {
        name: 'waterCosts',
        typeInfo: 'Double',
        attributeName: 'waterCosts',
        type: 'attribute'
    }, {
        name: 'controllable',
        typeInfo: 'Boolean',
        attributeName: 'controllable',
        type: 'attribute'
    }, {
        name: 'scalingOfControl',
        typeInfo: 'Double',
        attributeName: 'scalingOfControl',
        type: 'attribute'
    }]
}

谢谢!

推荐答案

您请求的功能现在在 Jsonix 2.3.2 Jsonix架构编译器 2.3.7

The feature you requested is now implemented in Jsonix 2.3.2 and Jsonix Schema Compiler 2.3.7.

Jsonix Schema Compiler现在生成必需 minOccurs maxOccurs 在生成的映射和JSON模式中。

Jsonix Schema Compiler now produces required, minOccurs and maxOccurs in the generated mappings and the JSON schema.

这是它在映射中的样子:

This is how it looks in the mappings:

  {
    localName: 'Items',
    propertyInfos: [{
        name: 'item',
        minOccurs: 0,
        maxOccurs: 100,
        collection: true,
        elementName: {
          localPart: 'item'
        },
        typeInfo: '.Items.Item'
      }]
  }

在JSON模式中:

    "Items":{
        "type":"object",
        "title":"Items",
        "properties":{
            "item":{
                "title":"item",
                "allOf":[
                    {
                        "type":"array",
                        "items":{
                            "$ref":"#/definitions/Items.Item"
                        },
                        "maxItems":100,
                        "minItems":0
                    }
                ],
                "propertyType":"element",
                "elementName":{
                    "localPart":"item",
                    "namespaceURI":""
                }
            }
        },
        "typeType":"classInfo",
        "typeName":{
            "localPart":"Items",
            "namespaceURI":""
        },
        "propertiesOrder":[
            "item"
        ]
    }

您可以从Jsonix上下文访问此元数据,如下所示:

You can access this metadata from the Jsonix context as follows:

    var context = new Jsonix.Context([ PO ]);
    var itemsClassInfo = context.getTypeInfoByName("PO.Items");
    var itemPropertyInfo = itemsClassInfo.getPropertyInfoByName("item");
    test.equal(false, itemPropertyInfo.required);
    test.equal(0, itemPropertyInfo.minOccurs);
    test.equal(100, itemPropertyInfo.maxOccurs);
    test.done();

这篇关于JSONIX:获取属性的限制和默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆