为什么属性类型从 float 变为 number?
Why do attributes type change from float to number?
我注意到,当我在 Orion 中注册具有某些 'float' 属性的实体时,经过一些更新后,类型更改为 'number' 而不是 'float'。
例如:
{ "id":"my_entity",
"type":"entity_type",
"attr1":{
"type":"float",
"value":"0.54",
"metadata":{}},
"attr2":{
"type":"Number",
"value":44.3,
"metadata":{}}}]
在这种情况下,当my_entity被注册时,两种类型的属性都是'float'。当对 attr2 的值进行一些更新时,其类型更改为 'Number'。这是正确的行为吗?
我认为这是由于默认输入造成的,如 NGSIv2 spec 中的 "Partial Representations" 部分所述:
Attribute/metadata type
may be omitted in requests. When omitted in attribute/metadata creation or in update operations, a default is used for the type depending on the value:
- If value is a string, then type
Text
is used
- If value is a number, then type
Number
is used.
- If value is a boolean, then type
Boolean
is used.
- If value is an object or array, then
StructuredValue
is used.
- If value is null, then
None
is used.
因此,您可能正在使用以下(或类似的)API 操作更新您的属性:
PUT /v2/entities/my_entity/attrs/attr2
{
"value": 44.3
}
和 type
有效负载中的遗漏会触发默认输入功能。
基本上,有两种解决方案:
在您的属性更新操作中使用type
:
PUT /v2/entities/my_entity/attrs/attr2
{
"type": "float",
"value": 44.3
}
使用属性值更新操作(不涉及类型或元数据):
PUT /v2/entities/my_entity/attrs/attr2/value
44.3
我注意到,当我在 Orion 中注册具有某些 'float' 属性的实体时,经过一些更新后,类型更改为 'number' 而不是 'float'。
例如:
{ "id":"my_entity",
"type":"entity_type",
"attr1":{
"type":"float",
"value":"0.54",
"metadata":{}},
"attr2":{
"type":"Number",
"value":44.3,
"metadata":{}}}]
在这种情况下,当my_entity被注册时,两种类型的属性都是'float'。当对 attr2 的值进行一些更新时,其类型更改为 'Number'。这是正确的行为吗?
我认为这是由于默认输入造成的,如 NGSIv2 spec 中的 "Partial Representations" 部分所述:
Attribute/metadata
type
may be omitted in requests. When omitted in attribute/metadata creation or in update operations, a default is used for the type depending on the value:
- If value is a string, then type
Text
is used- If value is a number, then type
Number
is used.- If value is a boolean, then type
Boolean
is used.- If value is an object or array, then
StructuredValue
is used.- If value is null, then
None
is used.
因此,您可能正在使用以下(或类似的)API 操作更新您的属性:
PUT /v2/entities/my_entity/attrs/attr2
{
"value": 44.3
}
和 type
有效负载中的遗漏会触发默认输入功能。
基本上,有两种解决方案:
在您的属性更新操作中使用
type
:PUT /v2/entities/my_entity/attrs/attr2 { "type": "float", "value": 44.3 }
使用属性值更新操作(不涉及类型或元数据):
PUT /v2/entities/my_entity/attrs/attr2/value 44.3