JSONIX:获取属性的限制和默认值
JSONIX: Get restrictions and default value for properties
我正在使用 JSONIX 编组和解组 XML 文件。到目前为止它运作良好。我缺少的是获得默认值和限制的可能性,例如 minOccours 和 maxOccours-Values。这在某种程度上可以用 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'
}]
}
谢谢!
免责声明:我是作者。
暂时没有,这个信息还没有生成。当年有this issue,但没有实现
如果您对此功能感兴趣,请提交两个问题 here(一个针对默认值,另一个针对 minOccurs
/maxOccurs
)。
原则上,此信息可从 XML 架构中获得,但在某些情况下,它无法清楚地映射到生成的模型。在一些奇怪的情况下,比如可重复的选择或顺序,这将不起作用,但在大多数情况下它会起作用。所以它是可实现的,请提交问题。
您是否只需要在生成的映射中包含这些内容?或者某种 API 来访问它?
您请求的功能现已在 Jsonix 2.3.2 and Jsonix Schema Compiler 2.3.7 中实现。
Jsonix 架构编译器现在在生成的映射和 JSON 架构中生成 required
、minOccurs
和 maxOccurs
。
这是它在映射中的样子:
{
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 上下文访问此元数据:
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 编组和解组 XML 文件。到目前为止它运作良好。我缺少的是获得默认值和限制的可能性,例如 minOccours 和 maxOccours-Values。这在某种程度上可以用 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'
}]
}
谢谢!
免责声明:我是作者。
暂时没有,这个信息还没有生成。当年有this issue,但没有实现
如果您对此功能感兴趣,请提交两个问题 here(一个针对默认值,另一个针对 minOccurs
/maxOccurs
)。
原则上,此信息可从 XML 架构中获得,但在某些情况下,它无法清楚地映射到生成的模型。在一些奇怪的情况下,比如可重复的选择或顺序,这将不起作用,但在大多数情况下它会起作用。所以它是可实现的,请提交问题。
您是否只需要在生成的映射中包含这些内容?或者某种 API 来访问它?
您请求的功能现已在 Jsonix 2.3.2 and Jsonix Schema Compiler 2.3.7 中实现。
Jsonix 架构编译器现在在生成的映射和 JSON 架构中生成 required
、minOccurs
和 maxOccurs
。
这是它在映射中的样子:
{
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 上下文访问此元数据:
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();